2016-04-12 12 views
-1

私は今問題なくファイル転送プラグインを使用しています。しかし、数日から、画像をアップロードするときにエラーが発生します。何が変わったのか分かりません。Ionic [2]ファイル転送でアップロードするときのコード1

私はFileTransferError.FILE_NOT_FOUND_ERRに等しいコード1を取得しています。しかし、それはどういう意味ですか?それは私の携帯電話で画像を見つけるのが難しいですか?または、サーバー上のイメージを見つける?誰もが考えている?

私はFileTransferErrorを返します。これは500のステータスとan error has occurredというメッセージを返しますが、それはすべて返されます。また、それは100%に行き、エラーを出します。

私のサーバー側のコード。

/// <summary> 
/// Saves a collection item and adds it to the collection 
/// </summary> 
/// <returns></returns> 
[HttpPost, Route("collections/save")] 
public async Task<IHttpActionResult> createItem() 
{ 
    if (!Request.Content.IsMimeMultipartContent()) 
     return InternalServerError(new Exception("UnsupportedMediaType")); 

    var provider = new CustomMultipartFormDataStreamProvider(ApiSettings.CollectionBasePath); 

    try 
    { 
     // Load the stream into buffer 
     Request.Content.LoadIntoBufferAsync().Wait(); 

     // Read all contents of multipart message into CustomMultipartFormDataStreamProvider. 
     await Request.Content.ReadAsMultipartAsync(provider); 
    } 
    catch (Exception ex) 
    { 
     return InternalServerError(new Exception($"Failed to read: {ex.Message}")); 
    } 

    return Ok();   
} 

/// <summary> 
/// Used to override an action within the MultipartFormDataStreamProvider 
/// This is needed to format the file name of a posted file 
/// </summary> 
internal class CustomMultipartFormDataStreamProvider : MultipartFormDataStreamProvider 
{ 
    public CustomMultipartFormDataStreamProvider(string path) : base(path) { } 

    /// <summary> 
    /// Takes the bodypart off of the filename string 
    /// </summary> 
    /// <param name="headers">the headers to mutate</param> 
    /// <returns>mutated filename</returns> 
    public override string GetLocalFileName(HttpContentHeaders headers) 
    { 
     return headers.ContentDisposition.FileName.Replace("\"", string.Empty); 
    } 
} 

マイアプリのコード

upload (baseUrl: string, string image, onSuccess: any, onFailed: any, onProgress: any) : void { 
    var ft = new FileTransfer(); 
    var options = new FileUploadOptions(); 

    options.fileKey = "file"; 
    options.fileName = filename; 
    options.mimeType = "image/jpeg" 
    options.chunkedMode = false; 
    options.headers = { 
     'Content-Type' : undefined 
    } 

    ft.onprogress = (e: ProgressEvent) => onProgress(e); 
    ft.upload(image, baseUrl + "collections/save", onSuccess, onFailed, options);    
} 

failed = (err: any) : void => { 
    var code = err.code; 
    console.log(err); 
    alert("Failed to upload image. Code: " + code); 
} 

onProgress = (progressEvent: ProgressEvent) : void => { 
    if (progressEvent.lengthComputable) { 
     var progress = Math.round((progressEvent.loaded/progressEvent.total) * 100); 
     //this.progress = progress; 
     this.setProgress(progress);  
    } 
} 

success = (result: any) : void => {    
    this.current++;   
    if(this.current <= this.total) {   
     // this.progress = 0;    
     this.setCurrent(this.current); 
     this.setProgress(0);    
     setTimeout(() : void => {  
      // give the animation time to reset   
      this.upload(this.collection.items[this.current - 1]); 
     },1000); 
    } else { 
     this.finished = true; 
    } 
} 

答えて

0

OKは、問題がサーバー側でした。 thisお返事ありがとうございます。

問題は、大きなファイルをアップロードしていたが、サーバーがそれらを受け付けなかったことだった。私が得ていたエラーは依然として非常に役に立たない。私は大きなファイルをアップロードすることが許可され、私のAPI

<system.web> 
    <httpRuntime maxRequestLength="30000000" /> 
</system.web> 

<system.webServer> 
    <security> 
     <requestFiltering> 
     <requestLimits maxAllowedContentLength="30000000" /> 
     </requestFiltering> 
    </security> 
</system.webServer> 

のweb.configファイルに次のように設定することにより

PS:downvoteに感謝し、なぜあなたがそれを落としたのか説明しません。よくやった。

関連する問題