I have a Web Api 2 it is calling another Web Api. The scenario is simple, I am uploading a file from Angular.Js. then Angular calls a web api, this web api calls another web api. The last web api takes 2 minutes to respond, so when the first web api times out (after 110 seconds), it is fired again. I have reproduced this issue in a clean environment and it is something that comes with Web Api. The problem it is I don't know how to tell my web api, I need more time to receive the answer from my request, any ideas? This is the first web api action, it doesn't help a lot but...
[HttpPost]
[MultipartContentValidator]
[ActionName("uploadfile")]
// POST /api/documents/uploadfile?folderId={folderId}&assetId={assetId}
public async Task<HttpResponseMessage> UploadFile(int folderId, int assetId)
{
IExternalWebApiCaller _caller = new ExternalWebApiCaller();
//## If it is not multipart, we throw it away
if (!Request.Content.IsMimeMultipartContent("form-data"))
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
//## Getting the juice in memory instead of the harddrive
var provider = await Request.Content.ReadAsMultipartAsync<InMemoryMultipartFormDataStreamProvider>(new InMemoryMultipartFormDataStreamProvider());
//## We get access to the data
NameValueCollection formData = provider.FormData;
//## It will access to the files
IList<HttpContent> files = provider.Files;
//## Reading a file as bytearray and creating the model
//## with the filename and stuff...if any
if (files != null)
{
HttpContent filetobeuploaded = files[0];
byte[] filebytearray = await filetobeuploaded.ReadAsByteArrayAsync();
DocumentUploadViewModel model = new DocumentUploadViewModel();
model.AssetId = assetId;
model.FolderId = folderId;
model.Data = filebytearray;
model.Filename = filetobeuploaded.Headers.ContentDisposition.FileName.Replace("\"", "");
return await _caller.CallWebApiHttpResponseMessage("api/document/uploadfile", HttpMethod.Post, null, model, GetHeaders());
}
else
{
//## Something fail (file with no content), so we kick this out
throw new HttpResponseException(HttpStatusCode.NoContent);
}
}
Aucun commentaire:
Enregistrer un commentaire