Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converting stream to buffer when uploading files without apparent need #922

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading