@@ -159,7 +159,7 @@ public function downloadFile(string $accessToken, string $refreshToken, string $
159159 'User-Agent ' => 'Nextcloud Dropbox integration ' ,
160160 'Dropbox-API-Arg ' => json_encode (['path ' => $ fileId ]),
161161 ],
162- 'stream ' => true ,
162+ 'sink ' => $ resource ,
163163 ];
164164
165165 $ response = $ this ->client ->post ($ url , $ options );
@@ -168,25 +168,13 @@ public function downloadFile(string $accessToken, string $refreshToken, string $
168168 if ($ respCode >= 400 ) {
169169 return ['error ' => $ this ->l10n ->t ('Bad credentials ' )];
170170 }
171-
172- $ body = $ response ->getBody ();
173- if (is_resource ($ body )) {
174- while (!feof ($ body )) {
175- // write ~5 MB chunks
176- $ chunk = fread ($ body , 5000000 );
177- fwrite ($ resource , $ chunk );
178- }
179- } else {
180- fwrite ($ resource , $ body );
181- }
182-
183171 return ['success ' => true ];
184172 } catch (ServerException |ClientException $ e ) {
185173 $ response = $ e ->getResponse ();
186174 if ($ response ->getStatusCode () === 401 ) {
187175 if ($ try > 3 ) {
188176 // impossible to refresh the token
189- $ this ->logger ->info ('Received the following response upon trying to download a file: ' . $ response -> getBody ()-> getContents () );
177+ $ this ->logger ->info ('Could not access file due to failed authentication. ' );
190178 return ['error ' => $ this ->l10n ->t ('Could not access file due to failed authentication. ' )];
191179 }
192180 $ this ->logger ->info ('Trying to REFRESH the access token ' , ['app ' => $ this ->appName ]);
0 commit comments