I'm wondering how to use AFNetworking to make a POST request with a file, a few parameters and progress report of the upload.
AFURLSessionManager's uploadTaskWithRequest:fromFile:progress:completionHandler works for POST upload with progress, but I cannot figure out how to add the POST parameters.
I've also looked into AFHTTPSessionManager's POST:parameters:constructingBodyWithBlock:success:failure:, but that doesn't appear to be able to report upload progress.
How do I get the best of both worlds?
Look at using a combination of uploadTaskWithStreamedRequest:progress:completionHandler: and multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:.
Related
I'm uploading 1900 contacts on my server through a POST API call (AFNetworking). It is taking some time to get a response from the server. During the upload I want to show a progress bar to show an estimated remaining upload time, as I'm not uploading any file , I use json string to post parameters.
Please help me with this, through Google search I could not find any help regarding the upload or download API.
There are multiple answers on StackOverflow already answering your specific use case. For example have a look at this question: get progress from dataTaskWithURL in swift
For your specific use case there are also already answers using AFNetworking: AFNetworking 3.x multipart form upload
To summarize, what you want to do is to
1. calculate the total amount of data you want to upload and the
2. total amount of data you already uploaded via the URLSession delegate methods.
Then you can bind this information to your UI element, for example your UIProgressView. Make sure that your upload tasks are asynchronous in order to have a non blocking upload task and to be able to update your UI while the upload is happening. This also means that other than your upload task your code to refresh the UI should run on the main thread. You can enforce this via DispatchQueue.main.async if needed.
I am trying to POST a file, and some string params to a .ashx page on my server from my iPad app using objc.
I have found lots of tutorials on how to post a file using objc, and I already have code to post strings. But I cant work out how to combine the two, so I can send multiple values in a single POST?
Could anyone help me out with an example or two? I am trying to avoid using 3rd party frameworks, so something using NSURLRequest would be preferred.
Thanks,
Mike
You need to use a multipart submission, with boundary strings, etc. Here's some helper code: https://github.com/Goles/SimpleHttpRequest from the answer to this question: Sending multipart POST from iOS and reading parameters in PHP $_POST?
As a followup to this question, I cannot get this to work so I need to take a step back I think.
Can someone post some sample code on how to post XML to a rest service WITHOUT using params? Is it even possible? Basically I have an object with several properties, and I convert this to XML and then need to upload it. But it fails if there is an image converted to string in the XML. Without that it works fine.
Even a JSON example would be helpful...
Totally blocked here :P
Use NSMutableURLRequest -setHTTPBody:, and set the Content-Type HTTP header to application/xml.
If you're doing this consistently, you may want to consider subclassing AFHTTPClient to add an XML parameter serialization option.
I have been using the Gdocs API to upload images without conversion. In the response, I used to see a thumbnail entry under feed.entry.link[x]. This appears to be missing since 2 days ago. Does anyone know if a change has been made to the API? Is there an alternate method of getting the thumbnail URL of an uploaded file?
Thanks!
Roderick Forsythe
I'm not aware of any change to the API, the thumbnail should still be available as the link with rel="http://schemas.google.com/docs/2007/thumbnail".
Can you show us your request and the response which doesn't include the thumbnail link?
EDIT: It takes a short amount of time before the thumbnail gets generated and you might not get it in the response of the creation request. It will show up if you GET the resource after you create it.
In a project, I recently replaced a simple form-based file upload with SWFUpload. When SWFUpload returns a success, I generate a form to add tags to the uploaded asset.
I'd like to be able to test inputting data into the tags textbox, but to do that I (think I) need to fake out SWFUpload.
Has anyone done this in the past? I haven't been able to find anything via google, and there doesn't seem to be anything in the cucumber docs re: testing Flash.
I dont think you need to fake flash at all, because all swfupload is doing for you is simulating a simple http post.
If you do a manual http post to the same action/controller that your swfupload is posting to and make sure the file field of your post is named the same as the swf parameter which swfupload passes (params[:Filedata]) you should get the same effect.
Also to answer Swanand's comment above you need to hack CGI::Session. Try http://blog.isshen.com/2008/10/5/making-swfupload-and-rails-2-1-sessions-work-together
I recently stumbled upon this plugin which may be able to help you with what yo need to do. You can read more here.