0

I am tryin to upload a video to Cloudinary (unsigned upload) using Swift 3, from a video url that I know for sure is there. I am trying to take the content of the local URL and turn it into Data, and then upload the data. I get a message:

Error Domain=com.cloudinary.error Code=400 "(null)" UserInfo={message=Invalid image file}

This is my code for uploading:

func approveFunc(){
    let config = CLDConfiguration(cloudName: "xxxxx", apiKey: "xxxxxx")
    let cloudinary = CLDCloudinary(configuration: config)

    let params = CLDUploadRequestParams(params: ["resource_type": "video" as AnyObject])
    var data: Data?
    do{
        data = try NSData(contentsOfFile: (self.videoURL.relativePath), options: NSData.ReadingOptions.alwaysMapped) as Data
    } catch {

    }
    cloudinary.createUploader().upload(data: data!, uploadPreset: "fycdpm" , params: params, progress: nil, completionHandler: {(response, error) in
        print("done")
        print(response)
        print(error)
    })
}

I also tried uploading directly from the file url:

    cloudinary.createUploader().upload(url: self.videoURL, uploadPreset: "fycdp7cm" , params: params, progress: nil, completionHandler: {(response, error) in
        print("done")
        print(response)
        print(error)
    })

And got the same error

Eyzuky
  • 1,843
  • 2
  • 22
  • 45

1 Answers1

2

It seems that the resource_type isn't passed, to the server, and therefore Cloudinary expects an image to be uploaded (the defaults), and errors. Have you tried to do the following?

let params = CLDUploadRequestParams().setResourceType(.video)

See the following for reference: https://github.com/cloudinary/cloudinary_ios/blob/master/CloudinaryTests/NetworkTests/UploaderTests.swift#L81-L104

Itay Taragano
  • 1,901
  • 1
  • 11
  • 12