Skip to content

Commit 89496b4

Browse files
author
Cerlin
committed
Updated `uploadPreFlight` method to have option for custom name
1 parent 05d6b3b commit 89496b4

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ So far this SDK has only machine to machine authentication mechanism and the fol
5959

6060
2. Methods available in `$file_service`
6161

62-
1. uploadPreFlight($file_path = "", $folder_id = 0);
63-
2. upload($file_path = "", $folder_id = 0, $filename = null); // If file name is null, filename will be derived from actual file name.
62+
1. uploadPreFlight($file_path = "", $folder_id = 0, $filename = null); // If filename is null, file name will be derived from actual file name.
63+
2. upload($file_path = "", $folder_id = 0, $filename = null); // If filename is null, file name will be derived from actual file name.
6464
3. getEmbedUrl($file_id)
6565
4. delete($file_id)
6666
5. destroyTrashedFile($file_id)

src/Box/Services/Files/FileService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,24 @@ public function __construct(AppAuth $app_auth)
2828
/**
2929
* @param $file_path string
3030
* @param $folder_id integer
31+
* @param $filename string
3132
* @return \GuzzleHttp\Psr7\Response
3233
*/
33-
public function uploadPreFlight($file_path = "", $folder_id = 0)
34+
public function uploadPreFlight($file_path = "", $folder_id = 0, $filename = null)
3435
{
3536
Assert::integerish($folder_id, "The folder id must be an integer. Got: %s");
3637

3738
$this->readFile($file_path);
3839

39-
$file_name = basename($file_path);
40+
$filename = ((!is_null($filename)) ? $filename : basename($file_path));
4041

4142
// Throws exception on 4XX response code
4243
return $this->guzzle_client->request(
4344
'OPTIONS',
4445
BAP::FILE_UPLOAD_PREFLIGHT,
4546
[
4647
"json" => [
47-
"name" => $file_name,
48+
"name" => $filename,
4849
"parent" => [
4950
"id" => (string)$folder_id
5051
],

0 commit comments

Comments
 (0)