asked    Dinah     2018-10-22       ios       75 view        1 Answer

[SOLVED] Why does the uploadprogress for Alamofire never reach a completion of 1.0 during upload?

I am able to successfully upload files using alamofire. However, I am trying to track the progress of the upload. What I am finding is that, although the upload is successful, as I can see my files successfully uploaded on to the server, the progress tracker never reaches 1.0. It tends to end between 8.00 - (under 1.0) but never reaching 1. This presents problems as I need to handle the completion of the file upload.

 Alamofire.upload(
        multipartFormData: { multipartFormData in
            for(key, value) in sendParamters{
                multipartFormData.append((value.data(using: .utf8)!), withName: key)
            }

            for fileURL in arrayURLToUpload{
                print("fileURL: \(fileURL)")
                multipartFormData.append(fileURL, withName: "file[]")
            }
    },
        to: UPLOAD_URL,
        encodingCompletion: { encodingResult in
            switch encodingResult {
            case .success(let upload, _, _):
                upload.responseJSON { response in
                    debugPrint(response)
                }

                /**TRACK PROGRESS OF UPLOAD**/
                upload.uploadProgress { progress in
                    print(progress.fractionCompleted) // NEVER REACHES 1.0

                    var progress = progress.fractionCompleted


                }
                /***/


            case .failure(let encodingError):
                print(encodingError)
            }
        }
    )

console:

 0.041737145652041
 0.521714320650513
 0.772137194562759

  1 Answer  

        answered    Lilith     2018-10-22      

You just need to change the postition of

upload.uploadProgress { progress in
                print(progress.fractionCompleted) // NEVER REACHES 1.0

with

  upload.responseJSON { response in
            debugPrint(response)
        }  

This is the correct usage:

Alamofire.upload(
        multipartFormData: { multipartFormData in
            for(key, value) in sendParamters{
                multipartFormData.append((value.data(using: .utf8)!), withName: key)
            }

            for fileURL in arrayURLToUpload{
                print("fileURL: \(fileURL)")
                multipartFormData.append(fileURL, withName: "file[]")
            }
    },
        to: UPLOAD_URL,
        encodingCompletion: { encodingResult in
            switch encodingResult {
            case .success(let upload, _, _):

             /**TRACK PROGRESS OF UPLOAD**/
                upload.uploadProgress { progress in
                    print(progress.fractionCompleted)
                }
                /***/




                upload.responseJSON { response in
                    debugPrint(response)
                }



            case .failure(let encodingError):
                print(encodingError)
            }
        }
    )




Your Answer





 2018-10-22         Hamiltion

Anchor link is not working from JSON string in ionic 3 and angular 4 : ur "<a (click)='openActionPage()'>terms and conditions</a>"

Am using this string in JSON file.In order to proceed, you need to agree with our "terms and conditions" and adding for accessing in frontend using <message *ngFor="let message of messages" [innerHTML]="message.content"> {{message.content}}</message>but the link openActionPage() is not opening in front end. Can anyone please suggest how me to solve this ? Thank you in advance so what you are trying to do here is to add dynamically some html code as innerHTML with anchor tag (a) and event binding to a method inside your ts file - this won't really work like...
 angular                     1 answers                     55 view
 2018-10-22         Brandon

Patching Items Doesn't Update Validity in Angular

I've a problem because after i submit the form, even though there's a value, the "field is required" doesn't disappear. It supposed to disappear. Is there something wrong with my validity? Please see this link See this link TSpatchValues(id, i) {let x = (<FormArray>this.addForm.controls['rows']).at(i);const selectedIngredient = this.ingredients.find(y => y.id == id);x.patchValue({ unit_price: selectedIngredient.price});} In these cases, you have to trigger a validity check with (for example) : x.patchValue({ unit_price: selectedIngredient.price});x.get('unit_...
 angular                     2 answers                     56 view
 2018-10-22         Norman

Month year picker in angular4 validation error

I am New in Angular4. I want a Month and year picker. I try this<dp-date-picker #searchFromPicker mode="month" theme="dp-material" onkeydown="return false" (onChange)="onChangeSearchFrom($event)"></dp-date-picker><button class="glyphicon glyphicon-calendar" style="padding-top:5px; padding-bottom:5px;" (click)="openSearchFrom()" [disabled]="!editable"></button>.But validation such as disable,min,max etc is not working in this example.Refer any better option if available other than this. Please help me. Try mater...
 angular                     1 answers                     56 view