iOS Error: Upload preset must be specified when using unsigned upload
I checked other posts, but that did not solve my issue.
My Cloudinary account setup is like this:
I have Folder-1, Folder-2, Folder-3 etc. I want to upload images onto respective folders depending on the use case.
I have enabled signed uploads for every folder.
What I am trying to achieve with the below server and iOS code:
So, having this setup, I am trying a signed upload of an image onto a particular folder - Folder-1 which has folder1_preset.
Server side - Node.js:
Code:
// let eager = 'w_400,h_300,c_pad|w_260,h_200,c_crop'
leteager = ''
letpublicImageID = utils.makeRandomString(12);
// Get the timestamp in seconds
vartimestamp = Math.round((newDate).getTime()/1000);
// Show the timestamp
console.log('Timestamp:',timestamp);
// Get the signature using the Node.js SDK method api_sign_request
varsignature = cloudinary.utils.api_sign_request(
{
timestamp:timestamp,
eager:eager,
public_id:publicImageID
},
process.env.API_SECRET
);
{
"digest":"61276599a89fed4ff8e888044873f54683d35af2",
"tstamp":1613612041,
"pubid":"oh_POmuLlJ5D"
}
let image = UIImage(named: "gearicon")
let imageData = image?.pngData()
let config = CLDConfiguration(cloudName: "MYCLOUDNAME", secure: true)
let cloudinary = CLDCloudinary(configuration: config)
CLDCloudinary.logLevel = .debug
let uploadParams = CLDUploadRequestParams()
.setPublicId("Folder-1/" + response.pubid!)
.setUploadPreset("folder1_preset")
.setResourceType("image")
uploadParams
.setSignature(
CLDSignature(
signature: response.digest,
timestamp: NSNumber(value: response.tstamp)
)
)
let request = cloudinary
.createUploader()
.signedUpload(
data: imageData!,
params: uploadParams,
progress: { (progress) in
// Handle progress
},
completionHandler: {(result, error) in
print("completed");
})
print(request)
I get the following error for singed upload. But I am using signedUpload method.
(lldb) expression debugPrint(error)
Optional(Error Domain=com.cloudinary.error Code=400 "(null)" UserInfo={message=
Upload preset must be specified when using unsigned upload
})() $R0 = {}
Please let me know what I am doing wrong.
-
Hello @Michael Kuperman:
the `response` object from the REST API has `digest` and response.digest is printing the right value that I received from my webservice.
The 4th line has response.digest
uploadParams
.setSignature(
CLDSignature(
signature: response.digest,
timestamp: NSNumber(value: response.tstamp)
)
)How do I validate if that is a "valid" signature?
-
Hi Chandra,
When looking at the logs on our side we see that the two uploads from the iOS SDK for your account which returned this error did not contain a signature and timestamp parameter as part of the upload API request. When a signature is invalid you would receive a different error message. The one you are seeing is due to the signature and timestamp parameters not being part of the upload request. In your iOS code, we don't see how the backend server is being called which then returns the 'response' object. May I please ask you to share that also? In addition, could you please print/log the value of `uploadParams` in your code before the upload request?
If you would like, you can submit those details privately/directly to us by creating a ticket using the following link:
https://support.cloudinary.com/hc/en-us/requests/new
Please sign in to leave a comment.
Comments
5 comments