Hello,
when i’m uploading a file with curl
curl -H Content-Type:"multipart/form-data" --form upload=@log.txt -v https://eu.backendlessappcontent.com/EE33A0E1-AXXD-XXXX-FFAA-XXXXXXXX/SERVER-CODE-KEY/files/app/3ce21651-b274-3277-e33faaaa-c5911914aae6?overwrite=true
my handlers are not called = no entry in the realtime log
curl result is the url to the uploaded file, i tried various folders and deleted / published different blocken/non-blocking handler. I tried the REST-API-KEY as well.
The reason is because you are using “Cloud Code API key”. That key must not be used outside of Backendless cloud logic as it unlocks API that should be used only from Cloud Code. Additionally, when you use that API key, other cloud code logic (such as event handlers) is not triggered.
Regards,
Mark
1 Like
thanks alot.
same topic, another problem, im trying to attach custom headers to the upload
curl -H Content-Type:"multipart/form-data" --form upload=@log.txt http://eu.backendlessappcontent.com/EE33A0E1-XXXX-XXXX-XXXX-XXXXXXXXXX/REST-API-KEY/files/app/test/test.txt?overwrite=true -H 'key: AAAA' -H 'secret: BBBB'
and read them with the Request HTTP Headers
block or even with the Request
, but its always null
in log:
11:45:55.792 | SERVER_CODE | INFO | [12280] { context: { ___jsonclass: 'com.backendless.servercode.RunnerContext', ___class: 'com.backendless.servercode.RunnerContext', deviceType: 'REST', crossHandlerData: {}, userLocale: null, httpHeaders: null, userId: null, eventContext: 'app/test/test.txt', userRoles: [ 'NotAuthenticatedUser' ], userToken: null, prematureResult: null, missingProperties: {}, appId: 'EE33A0E1-XXXXXXXXXXXXXXXX', httpResponseHeaders: {}, userRole: [ 'NotAuthenticatedUser' ] }, fileURL: 'https://eu.backendlessappcontent.com/XXXXXXXXXXXXX/REST-API-KEY/files/app/test/test.txt' }
Could you try checking in the beforeUpload handler?
Same problem on beforeUpload.
11:45:55.718 | SERVER_CODE | INFO | [10550] [9fda441a-a07b-4a23-8218-a16ff32c31c5] [INVOKE HANDLER] file.beforeUpload
11:45:55.723 | SERVER_CODE | INFO | [10550] { context: { ___jsonclass: 'com.backendless.servercode.RunnerContext', ___class: 'com.backendless.servercode.RunnerContext', deviceType: 'REST', crossHandlerData: {}, userLocale: null, httpHeaders: null, userId: null, eventContext: 'app/test/test.txt', userRoles: [ 'NotAuthenticatedUser' ], userToken: null, prematureResult: null, missingProperties: {}, appId: 'XXXXXXXXXXXXXX', httpResponseHeaders: {}, userRole: [ 'NotAuthenticatedUser' ] }, fileURL: 'https://eu.backendlessappcontent.com/EE33A0E1-XXXX-XXXX-XXXX-XXXXXXXXXX/REST-API-KEY/files/app/test/test.txt' }
It appears any custom headers with the file upload API call are not passed into Cloud Code. I just did a test with API services and the custom logic does get all the headers. An alternative approach might be sending the file to your API service (as a base64 encoded string for instance) along with the headers you need.
Regards,
Mark
is this a bug or intended behaviour? upload via rest in base64 is no option for the real usecase of uploading videos.
There was never a prior requirement like that, so this one would be classified as an improvement. Another workaround is to let them upload a video, the client gets the URL and then calls an API service to do post upload processing.
Regards,
Mark
ok, i gonna swtich to user-token then.