File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ export class FilesSearchService {
183
183
const blob : Blob = await fileDownloadResult . blob ( ) ;
184
184
return new File ( [ blob ] , fileName ) ;
185
185
} catch ( err ) {
186
- console . error ( `[FileBrowserService .fetchFileContent] Err='${ err . message } '` ) ;
186
+ console . error ( `[FileSearchService .fetchFileContent] Err='${ err . message } '` ) ;
187
187
return null ;
188
188
}
189
189
}
@@ -193,7 +193,10 @@ export class FilesSearchService {
193
193
*/
194
194
public downloadBingContent = async ( absoluteFileUrl : string , fileName : string ) : Promise < File > => {
195
195
try {
196
- const fileDownloadResult = await this . context . httpClient . get ( absoluteFileUrl , SPHttpClient . configurations . v1 ) ;
196
+ const fileDownloadResult = await this . context . httpClient . get ( absoluteFileUrl , SPHttpClient . configurations . v1 , {
197
+ method : "GET" ,
198
+ mode : "cors"
199
+ } ) ;
197
200
198
201
if ( ! fileDownloadResult || ! fileDownloadResult . ok ) {
199
202
throw new Error ( `Something went wrong when downloading the file. Status='${ fileDownloadResult . status } '` ) ;
@@ -203,7 +206,7 @@ export class FilesSearchService {
203
206
const blob : Blob = await fileDownloadResult . blob ( ) ;
204
207
return new File ( [ blob ] , fileName ) ;
205
208
} catch ( err ) {
206
- console . error ( `[FileBrowserService .fetchFileContent] Err='${ err . message } '` ) ;
209
+ console . error ( `[FileSearchService .fetchFileContent] Err='${ err . message } '` ) ;
207
210
return null ;
208
211
}
209
212
}
Original file line number Diff line number Diff line change @@ -56,6 +56,29 @@ export class OneDriveService extends FileBrowserService {
56
56
return filesQueryResult ;
57
57
}
58
58
59
+ /**
60
+ * Downloads document content from OneDrive location.
61
+ */
62
+ public downloadSPFileContent = async ( absoluteFileUrl : string , fileName : string ) : Promise < File > => {
63
+ try {
64
+ const fileDownloadResult = await this . context . spHttpClient . get ( absoluteFileUrl , SPHttpClient . configurations . v1 , {
65
+ method : "GET" ,
66
+ mode : "cors"
67
+ } ) ;
68
+
69
+ if ( ! fileDownloadResult || ! fileDownloadResult . ok ) {
70
+ throw new Error ( `Something went wrong when downloading the file. Status='${ fileDownloadResult . status } '` ) ;
71
+ }
72
+
73
+ // Return file created from blob
74
+ const blob : Blob = await fileDownloadResult . blob ( ) ;
75
+ return new File ( [ blob ] , fileName ) ;
76
+ } catch ( err ) {
77
+ console . error ( `[OneDriveService.fetchFileContent] Err='${ err . message } '` ) ;
78
+ return null ;
79
+ }
80
+ }
81
+
59
82
/**
60
83
* Gets users one drive personal documents library path
61
84
*/
@@ -147,4 +170,12 @@ export class OneDriveService extends FileBrowserService {
147
170
}
148
171
return this . oneDrivePersonalUrl ;
149
172
}
173
+
174
+ /**
175
+ * Creates an absolute URL
176
+ */
177
+ protected buildAbsoluteUrl = ( relativeUrl : string ) => {
178
+ const oneDriveHost = `https://${ this . oneDrivePersonalUrl . split ( "//" ) [ 1 ] . split ( "/" ) [ 0 ] } ` ;
179
+ return oneDriveHost + relativeUrl ;
180
+ }
150
181
}
You can’t perform that action at this time.
0 commit comments