Question

I have just upgraded from WebApi beta to the latest WebApi packages from NuGet. The visual studio project I am using targets .NET 4.0 and not 4.5.

I have been able to resolve all issues but one. I am uploading files using Multipart Form via the following code:

        // Verify that this is an HTML Form file upload request
        if (!Request.Content.IsMimeMultipartContent("form-data"))
        {
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
        }

        var task = Request.Content.ReadAsMultipartAsync();

        var dateField = task.Result.FirstDispositionNameOrDefault("expireby");

        if (dateField == null)
        {
            return this.SendResponse(HttpStatusCode.BadRequest, ":dateNotFound:");
        }

        var dateFieldValue = dateField.ReadAsStringAsync().Result;

        if (!DateTime.TryParse(dateFieldValue, out expireBy))
        {
            return this.SendResponse(HttpStatusCode.BadRequest, ":invalidDateFormat:");
        }

The method FirstDispositionNameOrDefault is not getting compiled anymore and I get the following error:

'System.Net.Http.MultipartMemoryStreamProvider' does not contain a definition for 'FirstDispositionNameOrDefault' and no extension method 'FirstDispositionNameOrDefault' accepting a first argument of type 'System.Net.Http.MultipartMemoryStreamProvider' could be found (are you missing a using directive or an assembly reference?)

Google did not return any relevant results. Can someone provide insight into this issue?

Était-ce utile?

La solution

It is true that the API you used in your codes was changed after Beta. It was designed to address following issue: http://aspnetwebstack.codeplex.com/workitem/53

And here's the change set http://aspnetwebstack.codeplex.com/SourceControl/changeset/8fda60945d49

If some additional instruction is helpful, here it is http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2

Regards, Troy

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top