Upload a zip to a geoprocessing service

464
1
10-23-2020 07:59 AM
todddoerr
New Contributor III

Hello,

I'm trying to upload a zip file using php and cURL library using Upload Item : but the file doesn't get uploaded.

I'm able to upload a file using that site using a web browser but no-go with php.

What am I doing wrong?

Thanks for your help.

Here's my code:

$LCPRequest = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/uploads/upload";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $LCPRequest);
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$cfile = curl_file_create('D:\Services\shapefiles\shapefiles.zip','application/zip','shapefiles.zip');
$requestParameters = array('file'=>$cfile, 'f'=>'pjson', 'description'=>'sample');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($requestParameters));

$output = curl_exec($ch);

print_r(curl_getinfo($ch));

curl_close($ch);

echo $output . "\r\n";

And here's my output:


Array
(
    [url] => https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/uploads/upload
    [content_type] => text/plain;charset=UTF-8
    [http_code] => 200
    [header_size] => 616
    [request_size] => 436
    [filetime] => -1
    [ssl_verify_result] => 20
    [redirect_count] => 0
    [total_time] => 0.266
    [namelookup_time] => 0.125
    [connect_time] => 0.157
    [pretransfer_time] => 0.219
    [size_upload] => 166
    [size_download] => 99
    [speed_download] => 372
    [speed_upload] => 624
    [download_content_length] => 99
    [upload_content_length] => 166
    [starttransfer_time] => 0.266
    [redirect_time] => 0
    [redirect_url] =>
    [primary_ip] => 52.4.149.135
    [certinfo] => Array
        (
        )

    [primary_port] => 443
    [local_ip] => xxxxxxxxx
    [local_port] => 50416
)


{
 "error": {
  "code": 500,
  "message": "Error performing upload operation",
  "details": []
 }
}

0 Kudos
1 Reply
LongDinh
Occasional Contributor II

Hi @todddoerr

I ran into the same issue with your sample url (works in web browser but programmatically, does not). When I tried in an ArcGIS Enterprise, it worked.

So perhaps this might be a limitation/restriction on ESRI's sample uploads server to prevent attacks? Do you have access to an ArcGIS Enterprise or ArcGIS Online service to test on?

0 Kudos