我通过@scott使用从答案下面的代码对这个问题How do I upload an image to a ServiceStack service?当上传图片/文件服务器,ServiceStack将引发UnauthorizedAccessException
[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" }});
}
我用这与我的DTO并在我的Android应用程序,但当我尝试发送它总是失败,并出现以下服务器错误:
{"ResponseStatus": {"ErrorCode":"UnauthorizedAccessException","Message":"'C:\\Windows\\SysWOW64\\inetsrv\\a.png' path denied.", 'C:\Windows\SysWOW64\inetsrv\a.png' path denied.
任何人都可以分享Monodroid ServiceStack图片上传样本?
谢谢。
好吧,我目前无法访问到服务器端,明天我会尝试(从Windows Server写入/更新AUTH)谢谢,我是全失去了我的时间,同时尝试老PCL库,我刚刚更新,并得到这方面的信息无论如何,谢谢 – 2014-09-28 17:05:17
你为什么-1我的问题? – 2014-09-28 17:05:51
@HâlukYilmaz不客气。我希望这会顺利。 – Scott 2014-09-28 17:07:44