2012-11-29 2 views
1

VB.NET MVC 4 WEB API를 사용하여 모바일 앱에서 웹 서비스 빌드로 이미지를 업로드하려고합니다. 모바일 앱은 성공적으로 PHP API에 업로드 할 수 있으므로 테스트 한 결과 웹 서비스에 문제가 있다는 것을 알았습니다. 웹 검색을했는데 파일 업로드를위한 샘플이 발견되지 않았습니다. 어떤 제안이라도 감사하겠습니다.Android에서 VB.NET MVC API로 파일 업로드

코드 :

Imports System.IO 
Imports System.Net.Http 
Public Class Pic 

Public Property pix As FileUpload 

Public Function addPic() As String 
    Try 

     Dim savedFile As String 
     savedFile = Path.GetFileName(Me.pix.PostedFile.FileName) 
     Me.pix.PostedFile.SaveAs("C:\tmp" + savedFile) 

    Catch exp As Exception 
     'Response.Write(exp.Message) 
    End Try 

    End Function 
End Class 

오류 :

No MediaTypeFormatter is available to read an object of type 'Pic' from content with media type 'multipart/form-data'.

예외 유형 :

System.InvalidOperationException

스택 트레이스 :

sys 인에 System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync (HttpContentContentExtensions.ReadAsentync) HttpContentExtensions.ReadAsAsync [T] (HttpContent 콘텐츠, 형식 형식, IEnumerable 1 formatters, IFormatterLogger formatterLogger)\r\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable 형식 자, IFormatterLogger formatterLogger) \ r \ n System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync IEnumerable을 1 formatters, IFormatterLogger formatterLogger)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Controllers.HttpActionBinding.<>c__DisplayClass1.<ExecuteBindingAsync>b__0(HttpParameterBinding parameterBinder)\r\n at System.Linq.Enumerable.WhereSelectArrayIterator 2.MoveNext() \ R \ n System.Threading.Tasks.TaskHelpers.IterateImpl (IEnumerator`1 열거, cancellationToken cancellationToken) "}에서

+1

http://stackoverflow.com/questions/7471179/ uploading-files-with-mvc-3 및 http://stackoverflow.com/questions/9660430/android-uploading-large-files - 둘 다 C#에 있지만 [CodeCoverter] (http : //converter.telerik. co.kr /) –

답변

1
Public Function Post()    
    Dim value1 As String = System.Web.HttpContext.Current.Request.Form("value1") 

     Dim image1 As HttpPostedFile = System.Web.HttpContext.Current.Request.Files("value2") 

     Dim filename As String = System.IO.Path.GetFileName(image1.FileName) 

     pix.SaveAs("c:\tmp\" + filename) 


    End Function