babu.desai@icloud.com's avatar

saving image to amazon s3 results in 6 bytes file

im sending uploads from my drop zone to s3 bucket, below is my function

public function addPhoto($id, Request $request) {

    $file = $request->file('file');
    $destinationPath = '/files/';
    $code = new Uuid(time().'_');
    $ext = '.' . $file->getClientOriginalExtension();
    $filename = $code . $ext;
    $s3 = \Storage::disk('s3')->put($destinationPath.$filename, 'public');

    $machine = Machine::findOrFail($id);

    $machine->photos()->create(['path' => $destinationPath.$filename]);
    return 'Done';
}

i can see the file gets uploaded to s3 bucket but its only 6 bytes.

0 likes
3 replies
rettigd's avatar
rettigd
Best Answer
Level 1

First, you are sourcing a string (public), not the file..try Storage::disk('s3')->put($destinationPath.$filename, $file);

babu.desai@icloud.com's avatar

wait now its just becoming 32 bytes file, still same problem. when i do $file as a source like you mentioned, it gives me type cast error ( fstat() expects parameter 1 to be resource, object given), so i did (string) $file. but that just makes it a 32 bytes file

rettigd's avatar

I'm using drop zone also, but my implementation is actually Storage::disk('s3')->put($destinationPath.$filename, file_get_contents($request->file));

Please or to participate in this conversation.