Question

I have to upload a pic taken from the camera to server.I took the image successfully and got an "asset url".When I print it I get something like "library://asset/asset.JPG?id=869A0C6A-A07B-4B53-8925-5A50765A062D&ext=JPG" .When I try to upload the file using the following code It is not uploaded.

I use the following code.It was given here https://stackoverflow.com/a/7411872/2270057

WebClient client = new WebClient();
 byte[] bret = client.UploadFile(path, "POST", FilePath);

I am using asset url in place of file path.Can someone help me? Do I have to make changes to the asset url?

Was it helpful?

Solution

Because of iOS sandboxing rules it's not possible to read data directly such URL. IOW your image does not belong to your application (it's not kept in it's directory).

What you can do is use the ALAssetRepresentation to get the image (and the options you want) data and then POST that data to your web server.

There's a few ways to do so but in general you can get CGImage from ALAssetRepresentation, which can be used to create an UIImage which can be converted to an NSData (representing a PNG or JPEG) and then you can get a System.IO.Stream usable to POST.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top