Skip to content

Commit

Permalink
fix: typeerror: url constructor: undefined is not a valid URL
Browse files Browse the repository at this point in the history
  • Loading branch information
uzenith360 committed Dec 17, 2023
1 parent 148bbb3 commit 36a75e1
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class FileUploadService {
}

private uploadFileToURL(uploadFileURL: string, file: File): Observable<HttpResponse<void> | HttpUploadProgressEvent> {
if (!uploadFileURL) {
return throwError(() => new HttpError('Upload URL is invalid', 0));
}

const pathname: string = (new URL(uploadFileURL)).pathname;

return this.http.put(
Expand All @@ -90,7 +94,7 @@ export class FileUploadService {
'ngsw-bypass': "true",
// This Content-Disposition is to force the browser to download file
// rather than preview it when the download button is clicked
'Content-Disposition': `attachment; filename=${file.name ?? pathname.substring(pathname.lastIndexOf('/') + 1)}`,
'Content-Disposition': `attachment; filename=${file.name ?? pathname.substring(pathname.lastIndexOf('/') + 1)}`,
},
observe: 'events',
reportProgress: !this.config.ignoreProgressReports,
Expand Down

0 comments on commit 36a75e1

Please sign in to comment.