Skip to content

Commit

Permalink
Merge pull request #922 from erickythierry/master
Browse files Browse the repository at this point in the history
converting stream to buffer when uploading files without apparent need
  • Loading branch information
PurpShell authored Jul 27, 2024
2 parents b8fb7e4 + abafce5 commit 07742e6
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/Utils/messages-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,28 +607,19 @@ export const getWAUploadToServer = (
let urls: { mediaUrl: string, directPath: string } | undefined
const hosts = [ ...customUploadHosts, ...uploadInfo.hosts ]

const chunks: Buffer[] = []
for await (const chunk of stream) {
chunks.push(chunk)
}

const reqBody = Buffer.concat(chunks)
fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64)

for(const { hostname, maxContentLengthBytes } of hosts) {
for(const { hostname } of hosts) {
logger.debug(`uploading to "${hostname}"`)

const auth = encodeURIComponent(uploadInfo.auth) // the auth token
const url = `https://${hostname}${MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`
let result: any
try {
if(maxContentLengthBytes && reqBody.length > maxContentLengthBytes) {
throw new Boom(`Body too large for "${hostname}"`, { statusCode: 413 })
}

const body = await axios.post(
url,
reqBody,
stream,
{
...options,
headers: {
Expand Down

0 comments on commit 07742e6

Please sign in to comment.