generated from hotwax/dxp-components
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from hotwax/#232z1wx
Implemented: service to prepare payload for upload and upload json file for import (#232z1wx)
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import api from '../api' | ||
import { UploadRequest } from '@/types' | ||
|
||
const uploadJsonFile = async (payload: any): Promise <any> => { | ||
return api({ | ||
url: "uploadJsonFile", | ||
method: "post", | ||
...payload | ||
}); | ||
} | ||
const prepareUploadJsonPayload = (request: UploadRequest) => { | ||
const blob = new Blob([JSON.stringify(request.uploadData)], { type: 'application/json'}); | ||
const formData = new FormData(); | ||
const fileName = (request.fileName ? request.fileName : Date.now() ) +".json"; | ||
formData.append("uploadedFile", blob, fileName); | ||
if (request.params) { | ||
for (const key in request.params) { | ||
formData.append(key, request.params[key]); | ||
} | ||
} | ||
return { | ||
data: formData, | ||
headers: { | ||
'Content-Type': 'multipart/form-data;' | ||
} | ||
} | ||
} | ||
|
||
export const UploadService = { | ||
prepareUploadJsonPayload, | ||
uploadJsonFile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface UploadRequest { | ||
params?: any; | ||
fileName?: string; | ||
uploadData: any; | ||
} |