我通過@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