@@ -39,7 +39,7 @@ qx.Class.define("osparc.file.FileUploader", {
3939
4040 events : {
4141 "uploadAborted" : "qx.event.type.Event" ,
42- "fileUploaded" : "qx.event.type.Event"
42+ "fileUploaded" : "qx.event.type.Data" ,
4343 } ,
4444
4545 statics : {
@@ -60,6 +60,7 @@ qx.Class.define("osparc.file.FileUploader", {
6060 members : {
6161 __presignedLinkData : null ,
6262 __uploadedParts : null ,
63+ __fileMetadata : null ,
6364
6465 // Request to the server an upload URL.
6566 retrieveUrlAndUpload : function ( file ) {
@@ -80,6 +81,14 @@ qx.Class.define("osparc.file.FileUploader", {
8081 . then ( presignedLinkData => {
8182 if ( presignedLinkData . resp . urls ) {
8283 this . __presignedLinkData = presignedLinkData ;
84+
85+ this . __fileMetadata = {
86+ location : presignedLinkData . locationId ,
87+ dataset : studyId ,
88+ path : presignedLinkData . fileUuid ,
89+ name : file . name
90+ } ;
91+
8392 try {
8493 this . __uploadFile ( file ) ;
8594 } catch ( error ) {
@@ -124,7 +133,7 @@ qx.Class.define("osparc.file.FileUploader", {
124133 const nProgress = Math . min ( Math . max ( 100 * progress - min , min ) , max ) ;
125134 this . getNode ( ) . getStatus ( ) . setProgress ( nProgress ) ;
126135 if ( this . __uploadedParts . every ( uploadedPart => uploadedPart [ "e_tag" ] !== null ) ) {
127- this . __checkCompleteUpload ( file ) ;
136+ this . __checkCompleteUpload ( ) ;
128137 }
129138 }
130139 } catch ( err ) {
@@ -153,7 +162,7 @@ qx.Class.define("osparc.file.FileUploader", {
153162 } ,
154163
155164 // Use XMLHttpRequest to complete the upload to S3
156- __checkCompleteUpload : function ( file ) {
165+ __checkCompleteUpload : function ( ) {
157166 if ( this . getNode ( ) [ "fileUploadAbortRequested" ] ) {
158167 this . __abortUpload ( ) ;
159168 return ;
@@ -162,29 +171,21 @@ qx.Class.define("osparc.file.FileUploader", {
162171 const presignedLinkData = this . __presignedLinkData ;
163172 this . getNode ( ) . getStatus ( ) . setProgress ( this . self ( ) . PROGRESS_VALUES . COMPLETING ) ;
164173 const completeUrl = presignedLinkData . resp . links . complete_upload ;
165- const location = presignedLinkData . locationId ;
166- const path = presignedLinkData . fileUuid ;
167174 const xhr = new XMLHttpRequest ( ) ;
168175 xhr . onloadend = ( ) => {
169- const fileMetadata = {
170- location,
171- dataset : this . getNode ( ) . getStudy ( ) . getUuid ( ) ,
172- path,
173- name : file . name
174- } ;
175176 const resp = JSON . parse ( xhr . responseText ) ;
176177 if ( "error" in resp && resp [ "error" ] ) {
177178 console . error ( resp [ "error" ] ) ;
178179 this . __abortUpload ( ) ;
179180 } else if ( "data" in resp ) {
180181 if ( xhr . status == 202 ) {
181- console . log ( "waiting for completion" , file . name ) ;
182+ console . log ( "waiting for completion" , this . __fileMetadata . name ) ;
182183 // @odeimaiz : we need to poll the received new location in the response
183184 // we do have links.state -> poll that link until it says ok
184185 // right now this kind of work if files are small and this happens fast
185- this . __pollFileUploadState ( resp [ "data" ] [ "links" ] [ "state" ] , fileMetadata ) ;
186+ this . __pollFileUploadState ( resp [ "data" ] [ "links" ] [ "state" ] ) ;
186187 } else if ( xhr . status == 200 ) {
187- this . __completeUpload ( fileMetadata ) ;
188+ this . __completeUpload ( ) ;
188189 }
189190 }
190191 } ;
@@ -196,30 +197,27 @@ qx.Class.define("osparc.file.FileUploader", {
196197 xhr . send ( JSON . stringify ( body ) ) ;
197198 } ,
198199
199- __pollFileUploadState : function ( stateLink , fileMetadata ) {
200+ __pollFileUploadState : function ( stateLink ) {
200201 const xhr = new XMLHttpRequest ( ) ;
201202 xhr . open ( "POST" , stateLink , true ) ;
202203 xhr . setRequestHeader ( "Content-Type" , "application/json" ) ;
203204 xhr . onloadend = ( ) => {
204205 const resp = JSON . parse ( xhr . responseText ) ;
205206 if ( "data" in resp && resp [ "data" ] && resp [ "data" ] [ "state" ] === "ok" ) {
206- this . __completeUpload ( fileMetadata ) ;
207+ this . __completeUpload ( ) ;
207208 } else {
208209 const interval = 2000 ;
209- qx . event . Timer . once ( ( ) => this . __pollFileUploadState ( stateLink , fileMetadata ) , this , interval ) ;
210+ qx . event . Timer . once ( ( ) => this . __pollFileUploadState ( stateLink ) , this , interval ) ;
210211 }
211212 } ;
212213 xhr . send ( ) ;
213214 } ,
214215
215- __completeUpload : function ( fileMetadata ) {
216+ __completeUpload : function ( ) {
216217 this . getNode ( ) [ "fileUploadAbortRequested" ] = false ;
217218
218- if ( "location" in fileMetadata && "dataset" in fileMetadata && "path" in fileMetadata && "name" in fileMetadata ) {
219- osparc . file . FilePicker . setOutputValueFromStore ( this . getNode ( ) , fileMetadata [ "location" ] , fileMetadata [ "dataset" ] , fileMetadata [ "path" ] , fileMetadata [ "name" ] ) ;
220- }
221219 this . __presignedLinkData = null ;
222- this . fireEvent ( "fileUploaded" ) ;
220+ this . fireDataEvent ( "fileUploaded" , this . __fileMetadata ) ;
223221 } ,
224222
225223 __abortUpload : function ( ) {
0 commit comments