Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error while upload file - Failed to open/read local data from file/application

Hi

I'm trying to upload a js resource file from my local machine using cloud shell.

I'm using the api mentioned below for the same.

I'm referring the api mentioned in this documentation - https://cloud.google.com/apigee/docs/api-platform/develop/resource-files

However I'm getting an error "(26) Failed to open read local data from file/application.

curl -X POST https://apigee(dot)googleapis(dot)com/v1/organizations/myorg/environments/test/resourcefiles?name=fileName.js
-H "Authorization: Bearer $TOKEN" \
-H "Content-type:multipart/form-data" \
-F file=@"/C:/Users/username/Downloads/fileName.js"

I tried providing path in multiple ways, still getting same error. Any help is appreciated. Thanks

0 1 426
1 REPLY 1

This seems like two issues here. 

  1. how to use the curl  syntax that uses the @ sign to de-reference a filename. (This is the source of the "failed to read local data" error message)
  2. how to upload an environment-scoped resource to Apigee.

The examples I have seen show it like this: 

curl -i -H "Content-Type: application/octet-stream" \
  -H "Authorization: Bearer $TOKEN" \
  -X POST \
  "https://apigee.googleapis.com/v1/organizations/$ORG/environments/$ENV/resourcefiles?type=jsc&name=foobar.js" \
  -d "@c:\Users\username\dev\scripts\my-file.js"

Notes:

  • content-type is octet-stream
  • I explicitly specify a type argument for the resource file type.
  • argument to curl is -d not -F
  • backslashes not forward slashes in the pathname of the @-referenced file. 

That assumes no WSL.  Have you tried that?  I just tried that from my Windows machine and it works.  (But I used PowerShell so the line-continuation characters were backticks not backslashes).