New url every request obtained by api #1034

Open
opened 2018-07-11 21:15:16 +00:00 by brettbeardall · 2 comments
brettbeardall commented 2018-07-11 21:15:16 +00:00 (Migrated from github.com)

Is there an easy way to use a different url, obtained via an api call, per file?

So:

  1. add files to queue
  2. user clicks upload all
  3. On each upload we obtain url from our api
  4. set url on uploader
  5. upload file
  6. repeat for next file
Is there an easy way to use a different url, obtained via an api call, per file? So: 1. add files to queue 2. user clicks upload all 3. On each upload we obtain url from our api 4. set url on uploader 5. upload file 6. repeat for next file
ph3n0m666 commented 2018-08-16 11:18:39 +00:00 (Migrated from github.com)

I had to do similar on this - by default all file urls are not defined, and then for each file in the queue, I had to make an api call to retrieve an upload location

For each upload location, I then had to update each item with the location (as it was doing chunk uploads)

As an example (and I hope it helps)

this.getUploadLocation().subscribe(item =>
        this.updateItem(this.uploadInProgress.uploader.queue[this.uploadedFiles], item)
      )

  getUploadLocation(){

    return this.http.post(api_to_get_upload_location',{},{observe: 'response'})
      .map( (res: HttpResponse<any>)=> {
        let resumableId = res.headers.get('Location').split('/objects/resumable/') [1];
        return {"location": res.headers.get('Location'), "resumableId": resumableId};
      });

updateItem(file, locationInfo){

    file.url = locationInfo.location;
    file.resumableId = locationInfo.resumableId;
   this.uploadInProgress.uploader.uploadItem(file);
  }
  }
I had to do similar on this - by default all file urls are not defined, and then for each file in the queue, I had to make an api call to retrieve an upload location For each upload location, I then had to update each item with the location (as it was doing chunk uploads) As an example (and I hope it helps) ``` this.getUploadLocation().subscribe(item => this.updateItem(this.uploadInProgress.uploader.queue[this.uploadedFiles], item) ) getUploadLocation(){ return this.http.post(api_to_get_upload_location',{},{observe: 'response'}) .map( (res: HttpResponse<any>)=> { let resumableId = res.headers.get('Location').split('/objects/resumable/') [1]; return {"location": res.headers.get('Location'), "resumableId": resumableId}; }); updateItem(file, locationInfo){ file.url = locationInfo.location; file.resumableId = locationInfo.resumableId; this.uploadInProgress.uploader.uploadItem(file); } } ```
jpike88 commented 2019-03-14 04:07:06 +00:00 (Migrated from github.com)

@ph3n0m666 it's a little hard to understand that code, are you able to paste a little more context?

@ph3n0m666 it's a little hard to understand that code, are you able to paste a little more context?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#1034