Skip to content

Upload files to Rest api #18

@alaa-nabawy

Description

@alaa-nabawy

Hi shuber,

I have an upload api i use it to upload files to google cloud storage and this is the api

http://acquired-backup-198200.appspot.com/upload?uname=arun&Description=description&players=arun,sai&community=true&Location=US&skills=batting&analysis=true

I use php-curl to upload files to this api and this is the php code

`if( $_SERVER['REQUEST_METHOD'] == 'POST' ){

	$file = $_FILES['files'];
	$fileName = $file['name'];
	$fileType = $file['type'];
	$fileTmp = $file['tmp_name'];
	var_dump( $file );
	$curl = curl_init();
	curl_setopt_array($curl, array(
	  CURLOPT_URL => "http://acquired-backup-198200.appspot.com/upload?uname=arun&Description=description&players=arun,sai&community=true&Location=US&skills=batting&analysis=true",
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => "",
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 30,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => "POST",
	  CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"filename\"; filename=\"". $fileName ."\"\r\nfile=\"filedir\"; filedir=\"@/home/alaa/Desktop/Cielo_estrellado_by_Eduardo_Diez_Viñuela.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
  CURLOPT_HTTPHEADER => array(
    "Cache-Control: no-cache",
    "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
};
}` 

And this is html

<form method="post" enctype="multipart/form-data"> <input type="file" name="files"> <input type="submit" name=""> </form>

The process succeed but the files in the storage are 0 bytes size so can you help me in that problem please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions