2

Need help with syntax to find a file in the documents directory not the main bundle so that I can upload the file with:

Alamofire.upload(fileUrl, to: serverUrl, method: .post)

The example in Alamofire documentation shows taking the file from the main bundle. I can use

var data = try Data(contentsOf: fileUrl)

But I do not want to convert file to data for upload. Is there a way I can overload the data and pass it? Any help/suggestions will be appreciated.

Thank you.

hacker_1989
  • 303
  • 4
  • 15
  • 1
    Why don't you want to convert the file to a Data object? – TheAmateurProgrammer Jan 17 '17 at 20:18
  • Suppose I have a 500 mb large image. I have stored it locally and I want to upload that image. I do 1. data = NSData(contentsOfFile: filePath) 2. var image = UIImage(data: data) 3. Check image orientation using extension like image.checkImageOrientation(). Then I convert the image to NSData using UIImageJPEGRepresentation it surges the memory usage to 4GBs. I do not want that the surge as it crashes the app. – hacker_1989 Jan 18 '17 at 19:26
  • If you're only uploading, why are you converting the data back into a UIImage – TheAmateurProgrammer Jan 18 '17 at 19:29
  • As, I need to check the image orientation before uploading. I know this is not a normal use case but I am curious to know other options as UIImageJPEGRepresentation always spikes memory if we use high resolution image. Like I have seen that for a 10MB very high resolution image, memory usage surges from 100mb to 1.3gb. – hacker_1989 Jan 18 '17 at 19:34
  • Thanks. I found the solution. Alamofire provides an API by which we can upload cached file directly. – hacker_1989 Jan 24 '17 at 20:51
  • Could you please help me to solve my issue, it is also associated with alamofire upload request http://stackoverflow.com/questions/41977486/how-to-upload-zip-data-with-alamofire – Sirop4ik Feb 01 '17 at 11:57
  • @hacker_1989 Can you share the exact API that you used. Would be great if you can post the code snippet as well. – Manish Kumar Jun 15 '17 at 11:48

0 Answers0