Upload images to server directory - iphone

I need to upload some images (taken from the camera or from photo library) to the server. The images are bonded to an user e each user can have one are more group of images bonded to a post, it will be like this:
User1 -> Post1 -> Image1, Image2
Post2 -> Image3
Post3 -> Image4, Image5, Image6
Each user will have his directory to store his images, and the image directory will have a directory to each post.
Server/../User1/Images/Post1
Server/../User1/Images/Post2
...
how can i send this images to the server and how can i create such directories to store it (if does not exist)?
I having some ideas how to accomplish that using http requests, but what's the best approach? Send the images directly from device or send it to a webservice e it will do the hard work?
Ether way i need some highlights how to accomplish it, i've never send images to a server from iOS before.
PS.: If someone knows to how to send more then one image on the same request i'll be grateful =)

Take a look at these previous SO posts regarding uploading an image from an iOS device to a server:
https://stackoverflow.com/questions/5752334/how-to-save-images-in-a-server-path-folder-from-iphone-application
iphone SDK : Upload image from iphone to a php Server send empty file ?(sample code link inside)
how to save image to server
How can i upload an image to server directory directly form iOS using FTP
Upload image to server from iOS device
post image to server in iphone
Save image taken from iPad/iPhone to sql server database base64

Related

Problems uploading images with "Share on LinkedIn"

So I am trying to post an image to my personal page through the new v2 LinkedIn API. I am sending the following data:
{"author":"urn:li:person:MYID","lifecycleState":"PUBLISHED","visibility":{"com.linkedin.ugc.MemberNetworkVisibility":"PUBLIC"},"specificContent":{"com.linkedin.ugc.ShareContent":{"shareMediaCategory":"IMAGE","shareCommentary":{"text":"Hello. Just testing the LinkedIn API."},"media":[{"status":"READY","originalUrl":"https:\/\/www.bbc.co.uk\/news","title":{"text":"BBC news"},"description":{"text":"A test post about BBC news"},"media":"urn:li:digitalmediaAsset:C4E22AQFmydgog-wKTw"}]}}}
As you'll see I've already uploaded the image and have a successful Asset ID and reference.
I get a successful id back from Linkedin: urn:li:share:651159824176993XXX but for some reason my image never appears?? What am I doing wrong?
Before creating the UGC post referencing the registered asset, you need to make sure that the asset is AVAILABLE, otherwise your image won't appear on LinkedIn.
When registering an asset, it goes through the following phases:
PROCESSING (LinkedIn probably does some optimizations to the image / checks if it's valid)
AVAILABLE (you should be good to go)
CLIENT_ERROR (or some other error I can't remember. Basically you should try it with a different asset)
For my app, before creating the UGC post with the image(s), I make sure the asset(s) is / are AVAILABLE first. How do I do that? By checking the status of each asset every 5 seconds with a timeout of 5 minutes (I tried it with a GIF once and to this day is still processing haha).
Once all assets are AVAILABLE, I create the UGC post referencing them, just like you did in your question.

Continue uploading NSData even connection lost/user clicked on home NSUrlConnection

I need to upload via HTTP Post NSData which is UIImage or NSUrl of a video file via the iPhone app which I develop for ios6
I need to support the following cases:
The user clicked on home - to continue uploading in background
The connection is lost - to continue uploading when there is a new internet connection even if the user left the app by clicking on the home button)
The user quit the app (clicked on x) and it was in the middle of uploading, next time that he would open the app, it will continue
In case 2 and 3:
It will continue from the same location that it was in the NSData (not start from the beginning of the file)
It will send in the new call a variable index={index} (where index is the amount of times that it continues starting from 0
I know how to use NSURLConnection as an async connection. But how to support the above 3 cases?
For this to work you need 2 things:
A record, stored persistently, of how much data has been uploaded to the server.
A server which accepts the Content-Range header and can handle storing partial uploads and completing them later. (or a server with an API to handle the same function).
If you have both of these things then you can perform the task using NSURLConnection and its delegate methods, NSUserDefaults (or similar) to store the progress information and subdataWithRange: (or perhaps NSFileHandle) to get only the data which needs to be uploaded.
Look at using connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite: to get updates of what data has been sent. Store that number (if not all of the data has been sent) into user defaults. Once all the data has been sent, remove the number from user defaults.
Use subdataWithRange: by creating a range from the stored number to the (total length of data - the number).

Google Drive Sdk- Audio & Video Streaming in iOS Application

Hi Google Drive Staff,
I have tried to stream video files from Google Drive(Without Downloading). But I gets alerts that Sign In. I have went thoroughly with Dr. Edit sample App but i did not found any solution. I tried with downloadUrl , embedLink, webContentLink, alternateLink. All gives message to sign In. When i tried with exportsLinks i get a Null Message. What is the problem Here. If U have any suggestion Please Let me Know...
I have tried with Google Drive for iOS in iPod, there we can stream Video without Downloading.
Please suggest me to resolve this issue
Thanks in Advance...
I could solve it just by appending the access_token to the download url
audiofile.strPath=[NSString stringWithFormat#"%#&access_token=%#",downloadUrl,accessToken];
pass the strPath to your avplayer object to play music.
I did not try the video part. but i think a similar approach should work.
you can fetch the access token from the GTMOAuth2Authentication object
Note that you might need to refresh it if its expires.
Hope this helps you.
Regards
Nitesh
I think it depends what you mean by "stream". Last time I looked, the download links all had a content disposition: attachment header, which instructs the browser to download rather than render the content.
If you have your own client fetching the url, you can choose to ignore that header and do what you like with the content as it is fetched. imho, it would be nice if the client could add a parameter to the url to indicate to the Google servers that it wants the content to be rendered v. downloaded, but hey ho.
You need to authorize all requests to downloadLinks with an Authorization header. Read more about the authorization and learn how to retrieve your users an access token on https://developers.google.com/drive/about-auth

How to send MMS using Native SDK + BB10

I have gone through the "Sending SMS sample" application and it's working fine. I have modified the code (only attachment) to send an MMS. I have a picture Lion.jpg in assets folder of the project. Picture size is less than 41KB.
Below is the modified code:
QUrl url("asset:///Lion.jpg");
messageBuilder->addAttachment(bb:im::message::Attachment("image/jpeg", "body.txt", url));
The rest of the code is same as in sending SMS. Code is compiled properly and run properly. But MMS wasn't received to another phone.
I have checked INBOX on my device, in which my code is running. It shows the message with no picture and a red clock-like icon. What am I doing wrong?
Unfortunately programmatically sending an MMS is not possible at this time.

How to handle file uploads to a dedicated image server?

I got a webserver with a running application. There's a webpage with a form: some text data and a file upload field. Now, what I would like to have is it working like this:
The file is sent to the dedicated server, diffrent then the one application is running on. The server should return some kind of path (or anything that identifies the uploaded and saved file and allows to create an URL). Then, both this path and user-filled data should be submitted to the webserver with application, for any kind of database storage.
Problem is, there are 2 diffrent servers, so I can't upload the file with javascript, can I? Another way would be just to use iframe and put the upload form in there - but then I think I can't access the result of the upload (still inside the iframe) with javascript to pass the file path to my main server.
I could also just upload the file to same server my application is running on and then just rsync it to the other one - but I'd like to avoid it if I can, trying to minimalize the traffic actually :)
How do you handle such thing in your applications?
If you used an iframe, you could submit the upload form to the dedicated image server, and in the case of a successful result, have it in turn load a page from the original server with the info (eg. image path) "passed along" as a GET parameter.
POST to dedicated server, server stores image and calls back to web server through a web service or other to give it any info required.