0
curl --location --request **PUT** 'https://REMOTE_SERVER/1177.png?v=3f75572bc00587e6104ed42d2e16a8f69656fdc63d50be78fb685266a2358340' --header 'Content-Length: 6137' --form 'File=@"/home/user/Documents/1177.png"'

im using postman / php code which creates the above curl , the issue I'm facing is it uploading all type of files but all the files seems to be corrupted and unable to open or load in the browser, following is set up as a remote server https://modules.prosody.im/mod_http_upload_external.html

  • only PUT is allowed here to upload files
  • in case of .txt file it looks good but it addes below code so it looks to me its because of some headers im missing or what not sure can you please help ?

-------------------- SOLUTION ---------------------

 $curl = curl_init();
        curl_setopt_array($curl, [
            CURLOPT_URL => "$remoteSever$fileName?v=$secretAuthToken",
            // CURLOPT_UPLOAD => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            //  CURLOPT_BINARYTRANSFER => true,
            //  CURLOPT_HEADER => false,
            // CURLOPT_CUSTOMREQUEST => 'PUT',
            CURLOPT_PUT => true,
            CURLOPT_INFILE => fopen($file->getRealPath(), 'rb'),
            CURLOPT_INFILESIZE => $fileSize,
            CURLOPT_SSL_VERIFYPEER => false,
//            CURLOPT_POSTFIELDS => [
//              'File'=> new \CURLFile($request->file('media_file'))
//              //  'File'=> $request->file('media_file')
//            ],
//            CURLOPT_HTTPHEADER => [
//                "Content-Length: $fileSize",
//                "Content-Type: $fileMimeType"
//            ],
        ]);

        $output = curl_exec($curl);
        curl_close($curl);
Milan Suthar
  • 352
  • 1
  • 2
  • 17

0 Answers0