jeudi 22 juin 2017

Amazon S3 hosted images not rendering in browser

We're uploading images to an amazon s3 bucket via Laravel with the following conditions:

$fileOptions = [
  'visibility' => 'public',
  'ContentType' => 'image/png',
  'ContentTransferEncoding' => 'base64'
  //'ContentType' => 'binary/octet-stream'
];

$this->lastUploadSuccess = Storage::disk($this->useDisk)
->getDriver()
->put( $_filePath.(strrpos($_filePath, "/")!=strlen($_filePath)-1?"/":"").$_fileName , $_fileContents , $fileOptions);

The upload itself works fine and the file is present and public but when trying to access it in a browser at the returned URL it's unable to render the file.

Inspector suggests it IS being sent with the file type that was set on upload

Accept-Ranges: bytes
Content-Type: image/png
Content-Length: 22290
Server: AmazonS3

Saving the file to the local computer and trying to open it there also returns OS specific flavours of

the file "filename.png" could not be opened    
It may be damaged or use a file format that Preview doesn’t recognize.

Opening it in a text editor indicates it IS the data that's being uploaded at $_fileContents (ie, the base64 or octet-stream) and no combination of ContentType and ContentTransferEncoding seems to get the image to render or download into a proper image file.

What is causing this problem and how can I fix it?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rGqZTT
via IFTTT

Aucun commentaire:

Enregistrer un commentaire