Compare commits

..

13 commits

Author SHA1 Message Date
David Wakelin
6b0f8f5e03 Added deprecation notice 2023-12-15 11:07:08 +00:00
David Wakelin
8ac092ea96 Version bump from bugfix 2023-12-15 11:06:58 +00:00
Aleksandar Kolakov
4f4b6148d2 Fixed hardcoded region in Spaces constructor 2023-12-15 10:30:35 +00:00
David Wakelin
6bc100cf90 Added move example to readme 2023-02-01 11:19:59 +00:00
David Wakelin
c52d22a70e Allowed passing validation flag to Space::file() 2022-11-11 09:55:47 +00:00
dependabot[bot]
3a32727c28 Bump guzzlehttp/guzzle from 7.4.3 to 7.4.5
Bumps [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) from 7.4.3 to 7.4.5.
- [Release notes](https://github.com/guzzle/guzzle/releases)
- [Changelog](https://github.com/guzzle/guzzle/blob/master/CHANGELOG.md)
- [Commits](https://github.com/guzzle/guzzle/compare/7.4.3...7.4.5)

---
updated-dependencies:
- dependency-name: guzzlehttp/guzzle
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-28 22:02:32 +01:00
dependabot[bot]
e9cdacc684 Bump guzzlehttp/guzzle from 7.4.2 to 7.4.3
Bumps [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) from 7.4.2 to 7.4.3.
- [Release notes](https://github.com/guzzle/guzzle/releases)
- [Changelog](https://github.com/guzzle/guzzle/blob/master/CHANGELOG.md)
- [Commits](https://github.com/guzzle/guzzle/compare/7.4.2...7.4.3)

---
updated-dependencies:
- dependency-name: guzzlehttp/guzzle
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-05-26 07:30:22 +01:00
David Wakelin
26d6b83356 Updated version numbers in github bug report template 2022-03-30 11:27:01 +01:00
David Wakelin
6d365b0f6a Bumped dependencies and released new minor version 3.5.0 up from 3.4.0 2022-03-30 11:25:19 +01:00
David Wakelin
de48ddb481 Added extra test assertion for Space::uploadFile mimeType argument
Added extra parameters for `Space::uploadFile` to docs
2022-03-30 11:21:42 +01:00
David Wakelin
f1adeb7c07
Merge pull request #74 from juhchamp/master
Add `mimetype` and `privacy` option to `uploadFile` method of `Space`
2022-03-30 11:13:53 +01:00
Juh Champ
dc5dc27ff3 uploadFile method of Space class updated and testCanUploadFileWithMimeType method added to SpaceTest. 2022-03-23 16:58:37 -03:00
Juh Champ
b7d1a40e70 The uploadFile method of Space class updated 2022-03-05 01:52:04 -03:00
8 changed files with 290 additions and 303 deletions

View file

@ -18,6 +18,9 @@ body:
label: Version label: Version
description: What version of Spaces-API is this occuring on? Versions below 3 will not be fixed. Please upgrade. description: What version of Spaces-API is this occuring on? Versions below 3 will not be fixed. Please upgrade.
options: options:
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.0 - 3.2.0
- 3.1.0 - 3.1.0
- 3.0.0 - 3.0.0

View file

@ -1,6 +1,7 @@
![Spaces-API](https://imgur.com/NYNsQyl.png "Devang Srivastava's Spaces-API") # This library is deprecated
We recommend using the [official SDK](https://github.com/DigitalOceanPHP/Client) or the [Laravel package](https://github.com/GrahamCampbell/Laravel-DigitalOcean)
PHP library for accessing Digital Ocean spaces All issues will be closed and new PRs will not be accepted
## Installation ## Installation
Install via composer Install via composer
@ -32,6 +33,9 @@ $file2url = $file2->getSignedURL("2 hours");
// Make a copy // Make a copy
$file3 = $file2->copy('remote-file-3.txt'); $file3 = $file2->copy('remote-file-3.txt');
// Move or rename a file
$file2->move('new-filename.txt')
// Make a file public and get the URL // Make a file public and get the URL
$file3->makePublic(); $file3->makePublic();
$file3url = $file3->getURL(); $file3url = $file3->getURL();

View file

@ -303,15 +303,19 @@ class Space
* *
* @param string $filepath The path to the file, including the filename. Relative and absolute paths are accepted. * @param string $filepath The path to the file, including the filename. Relative and absolute paths are accepted.
* @param string|null $filename The remote filename. If `null`, the local filename will be used. * @param string|null $filename The remote filename. If `null`, the local filename will be used.
* @param string|null $mimeType The file mime type to pass as ContentType for the file (e.g. 'image/jpeg').
* @param bool $private True for the file to be private, false to allow public access.
* *
* @return \SpacesAPI\File * @return \SpacesAPI\File
*/ */
public function uploadFile(string $filepath, ?string $filename = null): File public function uploadFile(string $filepath, ?string $filename = null, ?string $mimeType = null, bool $private = true): File
{ {
$this->s3->putObject([ $this->s3->putObject([
'Bucket' => $this->name, 'Bucket' => $this->name,
'Key' => ($filename) ?: basename($filepath), 'Key' => ($filename) ?: basename($filepath),
'SourceFile' => $filepath, 'SourceFile' => $filepath,
'ContentType' => $mimeType,
'ACL' => ($private) ? 'private' : 'public-read'
]); ]);
return new File($this, ($filename) ?: basename($filepath), [], false); return new File($this, ($filename) ?: basename($filepath), [], false);
@ -321,13 +325,14 @@ class Space
* Get an instance of \SpacesAPI\File for a given filename * Get an instance of \SpacesAPI\File for a given filename
* *
* @param string $filename * @param string $filename
* @package bool $validate
* *
* @return \SpacesAPI\File * @return \SpacesAPI\File
* @throws \SpacesAPI\Exceptions\FileDoesntExistException Thrown if the file doesn't exist * @throws \SpacesAPI\Exceptions\FileDoesntExistException Thrown if the file doesn't exist
*/ */
public function file(string $filename): File public function file(string $filename, bool $validate = true): File
{ {
return new File($this, $filename); return new File($this, $filename, [], $validate);
} }
/** /**

View file

@ -36,7 +36,7 @@ class Spaces
{ {
$this->s3 = new S3Client([ $this->s3 = new S3Client([
"version" => "latest", "version" => "latest",
"region" => "us-east-1", "region" => $region,
"endpoint" => "https://$region.$host", "endpoint" => "https://$region.$host",
"credentials" => ["key" => $accessKey, "secret" => $secretKey], "credentials" => ["key" => $accessKey, "secret" => $secretKey],
"ua_append" => "SociallyDev-Spaces-API/2", "ua_append" => "SociallyDev-Spaces-API/2",

View file

@ -1,7 +1,7 @@
{ {
"name": "sociallydev/spaces-api", "name": "sociallydev/spaces-api",
"description": "Library for accessing Digital Ocean spaces", "description": "Library for accessing Digital Ocean spaces",
"version":"3.4.0", "version":"3.6.1",
"type": "library", "type": "library",
"license": "MIT", "license": "MIT",
"authors": [ "authors": [

549
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -180,7 +180,7 @@ Recursively download an entire directory.
**Description** **Description**
```php ```php
public file (string $filename) public file (string $filename, bool $validate = true)
``` ```
Get an instance of \SpacesAPI\File for a given filename Get an instance of \SpacesAPI\File for a given filename
@ -190,6 +190,8 @@ Get an instance of \SpacesAPI\File for a given filename
**Parameters** **Parameters**
* `(string) $filename` * `(string) $filename`
* `(bool) $validate`
: Whether to validate the file exits. Defaults to `true`
**Return Values** **Return Values**
@ -463,7 +465,7 @@ Recursively upload an entire directory
**Description** **Description**
```php ```php
public uploadFile (string $filepath, string|null $filename = null) public uploadFile (string $filepath, string|null $filename = null, string|null $mimeType = null, bool $private = true)
``` ```
Upload a file Upload a file
@ -476,6 +478,10 @@ Upload a file
: The path to the file, including the filename. Relative and absolute paths are accepted. : The path to the file, including the filename. Relative and absolute paths are accepted.
* `(string|null) $filename` * `(string|null) $filename`
: The remote filename. If `null`, the local filename will be used. Default `null` : The remote filename. If `null`, the local filename will be used. Default `null`
* `(string|null) $mimeType`
: The files mimeType. If `null` the mimeType is inferred from the file by DigitalOcean Spaces. Default `null`
* `(bool)` $private
: If `true` then the file is private, if `false` the file is publicly available. Default `true`
**Return Values** **Return Values**

View file

@ -86,6 +86,14 @@ class SpaceTest extends TestCase
$this->assertInstanceOf(File::class, $file); $this->assertInstanceOf(File::class, $file);
} }
public function testCanUploadFileWithMimeType()
{
$tmpFile = tempnam(sys_get_temp_dir(), 'spaces-test');
$file = self::$space->uploadFile($tmpFile, 'upload-test.txt', 'text/plain');
$this->assertInstanceOf(File::class, $file);
$this->assertEquals('text/plain', $file->content_type);
}
/** /**
* @depends testCanUploadText * @depends testCanUploadText
* @depends testCanUploadFile * @depends testCanUploadFile