0
votes

I would like to use cURL to not only send data parameters in HTTP POST but to also upload files with specific name. How should I go about doing that ?

the api also gives example of how to do the curl command

curl -k -F file=@/path/to/file.txt -F apiId={apiId} -F apiSecretId={apiSecretId} https:\/\/fa2a.ninjastream.to\/api\/file\/upload?expires=1596028934&signature=132d1332996262809c7cc2dcd6376c483d6521dc7c273f9275ee1acb53e0b072

so this is the function i have

function uploadfileandgetlink($uploadurl){
  
          $ch = curl_init();

          curl_setopt($ch, CURLOPT_URL, $uploadurl);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  
  
 
          $post = array(
            
            
              'file'  => '@beztam.mp4',
              'apiId' => 'sdfg',
              'apiSecretId' => 'dsfg'
          );
          curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

          echo $result = curl_exec($ch);
          if (curl_errno($ch)) {
              echo 'Error:' . curl_error($ch);
          }
          curl_close($ch);

the response i get is {"status":"error","message":"No file inputted"}

Update : fixed by replacing string @beztam.mp4 to curl_file_create(__DIR__ .'/beztam.mp4')

1
Have you looked at CURLFile? - Professor Abronsius
@ProfessorAbronsius thanks so much i tried it worked like a charm - Seddek Iguijji
Excellent! Glad that worked - good luck with the rest of your project - Professor Abronsius
Excellent! Glad that worked - good luck with the rest of your project - Professor Abronsius

1 Answers

0
votes

You can use:

$fileContent = file_get_contents('beztam.mp4'); 
$post = array(
            
            
              'file'  => rawurlencode($fileContent),
              'apiId' => 'sdfg',
              'apiSecretId' => 'dsfg'
          );