i got refeer from this link How do I upload an image to a ServiceStack service?
[Route("/upload","POST")] public class UploadFileRequest { // Example of other properties you can send with the request public string[] Tags { get; set; } }
class MyFileService : Service
{
public bool Post(UploadFileRequest request)
{
// Check a file has been attached
if(Request.Files == null || Request.Files.Length == 0)
throw new HttpError(400, "Bad Request", "No file has been uploaded");
// Save the file
Request.Files[0].SaveTo(Request.Files[0].FileName);
// Maybe store the tags (or any other data in the request)
// request.Tags
return true;
}
}
Then with the JsonServiceClient in your Android app, then your simply need to do this:
var filename = "cab.jpg"; // The path of the file to upload
var client = new JsonServiceClient("http://212.175.132.168/service/api/");
using(var fileStream = File.OpenRead(filename))
{
client.PostFileWithRequest<bool>(fileStream, "cab.jpg", new UploadFileRequest { Tags = new[] { "Cab", "Taxis", "NewYork", "Yellow" }});
}
i used on dto and used on my android app, but when i try to send, it says empty or no file also on server get server error
is there something wrong?
and secondly, how can i get selected image location path;
i used http://developer.xamarin.com/recipes/android/other_ux/pick_image/ from whole image but i always get null or empty file error
can anyone share monodroid servicestack image upload sample?
thanks
0 comments:
Post a Comment