fix: upload for product

This commit is contained in:
Adhiraj Singh
2022-09-02 20:09:54 +05:30
parent 9e581f59cb
commit 765dcc1d1f
5 changed files with 24 additions and 10 deletions

View File

@@ -121,6 +121,15 @@ export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | str
}
}
export const encodeBase64EncodedStringForUpload = (b64: string) => (
encodeURIComponent(
b64
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/\=+$/, '')
)
)
export const generateProfilePicture = async(mediaUpload: WAMediaUpload) => {
let bufferOrFilePath: Buffer | string
if(Buffer.isBuffer(mediaUpload)) {
@@ -501,6 +510,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger }: C
}
const reqBody = Buffer.concat(chunks)
fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64)
for(const { hostname, maxContentLengthBytes } of hosts) {
logger.debug(`uploading to "${hostname}"`)