@@ -72,36 +72,51 @@ class {{ service.name | caseUcfirst }} extends Service
72
72
' {{ key }}' => ' {{ header }}' ,
73
73
{% endfor % }
74
74
], $params );
75
- } else {
76
- $id = ' ' ;
77
- $handle = @ fopen (${{ parameter . name | caseCamel }}, " rb" );
78
- $counter = 0 ;
79
- $headers = [' content-type' => ' multipart/form-data' ];
80
- while (! feof ($handle )) {
81
- $params [' {{ parameter.name }}' ] = new \CURLFile (' data://' . $mimeType . ' ;base64,' . base64_encode (@ fread ($handle , Client :: CHUNK_SIZE )), $mimeType , $postedName );
82
- $headers [' content-range' ] = ' bytes ' . ($counter * Client :: CHUNK_SIZE ) . ' -' . min (((($counter * Client :: CHUNK_SIZE ) + Client :: CHUNK_SIZE ) - 1 ), $size ) . ' /' . $size ;
83
- if (! empty ($id )) {
84
- $headers [' x-{{spec.title | caseLower }}-id' ] = $id ;
85
- }
86
- $response = $this -> client -> call(Client :: METHOD_POST , $path , $headers , $params );
87
- $counter ++ ;
88
- if (empty ($id )) {
89
- $id = $response [' $id' ];
90
- }
91
- if ($onProgress ! == null ) {
92
- $end = min (((($counter * Client :: CHUNK_SIZE ) + Client :: CHUNK_SIZE ) - 1 ), $size );
93
- $onProgress ([
94
- ' $id' => $response [' $id' ],
95
- ' progress' => min (($counter + 1 ) * Client :: CHUNK_SIZE , $size ) / $size * 100 ,
96
- ' sizeUploaded' => $end + 1 ,
97
- ' chunksTotal' => $response [' chunksTotal' ],
98
- ' chunksUploaded' => $response [' chunksUploaded' ]
99
- ]);
75
+ }
76
+
77
+ $id = ' ' ;
78
+ $counter = 0 ;
79
+
80
+ {% for parameter in method . parameters . all % }
81
+ {% if parameter . isUploadID % }
82
+ if (${{ parameter . name | caseCamel | escapeKeyword }} ! = ' unique()' ) {
83
+ try {
84
+ $response = $this -> client -> call(Client :: METHOD_GET , new URL ($path . ' /' . {{ parameter . name }}), headers );
85
+ $counter = $response [' chunksUploaded' ] ?? 0 ;
86
+ } catch (\ Exception $e ) {
100
87
}
101
88
}
102
- @ fclose ($handle );
103
- return $response ;
89
+ {% endif % }
90
+ {% endfor % }
91
+
92
+ $headers = [' content-type' => ' multipart/form-data' ];
93
+ $handle = @ fopen (${{ parameter . name | caseCamel }}, " rb" );
94
+ $start = $counter * Client :: CHUNK_SIZE ;
95
+ while ($start < $size ) {
96
+ fseek ($handle , $start );
97
+ $params [' {{ parameter.name }}' ] = new \CURLFile (' data://' . $mimeType . ' ;base64,' . base64_encode (@ fread ($handle , Client :: CHUNK_SIZE )), $mimeType , $postedName );
98
+ $headers [' content-range' ] = ' bytes ' . ($counter * Client :: CHUNK_SIZE ) . ' -' . min (((($counter * Client :: CHUNK_SIZE ) + Client :: CHUNK_SIZE ) - 1 ), $size ) . ' /' . $size ;
99
+ if (! empty ($id )) {
100
+ $headers [' x-{{spec.title | caseLower }}-id' ] = $id ;
101
+ }
102
+ $response = $this -> client -> call(Client :: METHOD_POST , $path , $headers , $params );
103
+ $counter ++ ;
104
+ $start + = Client :: CHUNK_SIZE ;
105
+ if (empty ($id )) {
106
+ $id = $response [' $id' ];
107
+ }
108
+ if ($onProgress ! == null ) {
109
+ $onProgress ([
110
+ ' $id' => $response [' $id' ],
111
+ ' progress' => min (((($counter * Client :: CHUNK_SIZE ) + Client :: CHUNK_SIZE ) - 1 ), $size ) / $size * 100 ,
112
+ ' sizeUploaded' => min ($counter * Client :: CHUNK_SIZE ),
113
+ ' chunksTotal' => $response [' chunksTotal' ],
114
+ ' chunksUploaded' => $response [' chunksUploaded' ],
115
+ ]);
116
+ }
104
117
}
118
+ @ fclose ($handle );
119
+ return $response ;
105
120
{% endif % }
106
121
{% endfor % }
107
122
{% else % }
0 commit comments