uploadcare / uploadcare-swift

Swift API client for iOS, iPadOS, tvOS, macOS, and Linux handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.
https://uploadcare.com/
MIT License
12 stars 6 forks source link

Errors while uploading #128

Closed AlexPerathoner closed 9 months ago

AlexPerathoner commented 9 months ago

Question

I'm trying to upload a local image to Uploadcare using the Swift Api inside of a Finder Extension. Calling directUpload(files:store:metadata:uploadSignature:_:_:) brings the following errors:

Background URLSession adopters are required to have com.apple.application-identifier entitlement.
The request of a upload task should not contain a body or a body stream, use `uploadTask(with:fromFile:)` or supply the body stream through the `urlSession(_:needNewBodyStreamForTask:)` delegate method.
ResumableUploadState: cannot initWithOriginalRequest with nil request
API MISUSE: Resuming an NSURLSessionTask with nil URL.

The Image is simply read from disk with Data(contentsOf: fileURL). The Extension target has the App Sandbox + Outgoing Connections + Hardened Runtime Capabilities. Doing simple URLRequest is possible and works without errors. Public and Secret keys work, too: the python example in the docs works just fine - the swift doesn't even compile.

Running on macOS 14.3; Swift 5.9.2;

Am I missing something? Are the docs for swift completely out-of-date? Am I supposed to add some capability?

AlexPerathoner commented 9 months ago

Just noticed while debugging with Xcode the following warning is shown: immagine

However directUpload(files:uploadType:store:metadata:uploadSignature:_:_:) is only called by:

AlexPerathoner commented 9 months ago

Looks like it was indeed because of this runtime issue. Setting the body to nil solved it. Similar to https://github.com/google/GoogleUtilities/pull/114 I'll create a PR