0

im trying to download the file from dropbox using v2 api and upload it to amazon s3

to download file here is what i did:

$headers= array( 'Content-Type: ', "Authorization: Bearer EkOrS5mbVAwA....", "Dropbox-API-Arg: {\"path\": \"/clients/erbrecht, kenneth/2nd dispute erbrecht.docx\"}"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/download'); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, 1); //curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); 

the code above returned response in "application/octet-stream" i assume, so my first problem is to convert this stream to a file and upload it to s3

i have this code that takes physical path of the file and upload it to s3 but in the above case i have the stream

try{ $s3 = Aws\S3\S3Client::factory(array( 'region' => S3_REGION, 'version' => 'latest', 'credentials' => array( 'key' => S3_ACCESS_KEY, 'secret' => S3_SECRET_KEY, ) )); $s3->putObject([ 'Bucket' => $this->s3bucket, 'Key' => "uploads/{$name}", 'Body' => fopen($path,'rb'), 'ACL' => 'public-read' ]); return ''; }catch(S3Exception $e){ //return $e->getMessage(); return 'Error Uploading File, Please try again'; } 

so the problem is to convert stream to file and upload to s3, how can i change the above code to do that

Thanks in advance.

5
  • application/octet-stream doesn't mean "stream" in the sense that you're thinking. It simply means that nature of the contents of the file are binary but otherwise of an unknown/uninteresting type, as far as the browser should care -- it shouldn't try to interpret the content, it should just allow the content to be saved to a file. I could be mistaken, but I believe your actual question seems to be "how do I download with curl and save to a file so that I can upload that file to S3?" Commented Feb 21, 2017 at 10:46
  • yes correct i want the content to be converted to file so i can upload on s3 Commented Feb 21, 2017 at 10:47
  • 1
    stackoverflow.com/a/6409531/1695906 Commented Feb 21, 2017 at 10:48
  • thanks @Michael-sqlbot it worked! :) Commented Feb 21, 2017 at 12:48
  • I wish that close message didn't say "exact duplicate," but given that the solution in the other answer took care of the real issue at hand, I think the closure is probably appropriate. Commented Feb 22, 2017 at 0:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.