Skip to content

Commit

Permalink
Use multipart boundary exactly like FF does
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Edwards committed May 14, 2024
1 parent b810cd4 commit c1e2cde
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Crypter.Web/wwwroot/chromiumFetchTest/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ function wait(milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}

const boundaryText = 'CustomBoundary';
const boundaryText = '4c4b7e34-dc34-4971-913c-6b6ceb09ee33';

function uploadAsync(file) {
const readableStream = new ReadableStream({
async start(controller) {
controller.enqueue(`\r\n--${boundaryText}\r\n`);
controller.enqueue('Data={"Filename":"test.txt", "ContentType":"text/csv", "PublicKey":"nxC6b2L5fWjLROFbNMmBxRX1GSC3nCSwU/GaM3hC4hk=", "KeyExchangeNonce":"JAdv1MbzC7BGNiWfC+3JTinCEhf/+JUl0ySNeQfC7q4=", "Proof":"i51Bn7mHZDcZ0u4xnd1CtyEL9RXJDjheogPHrv2vB5c=", "LifetimeHours":24};type=application/json');
controller.enqueue(`\r\n--${boundaryText}\r\n`);
controller.enqueue('Ciphertext=')

controller.enqueue(`--${boundaryText}`);
controller.enqueue('\r\n');
controller.enqueue('Content-Type: application/json; charset=utf-8');
controller.enqueue('\r\n');
controller.enqueue('Content-Disposition: form-data; name=Data');
controller.enqueue('\r\n\r\n');
controller.enqueue('{"Filename":"test.txt", "ContentType":"text/csv", "PublicKey":"nxC6b2L5fWjLROFbNMmBxRX1GSC3nCSwU/GaM3hC4hk=", "KeyExchangeNonce":"JAdv1MbzC7BGNiWfC+3JTinCEhf/+JUl0ySNeQfC7q4=", "Proof":"i51Bn7mHZDcZ0u4xnd1CtyEL9RXJDjheogPHrv2vB5c=", "LifetimeHours":24}');
controller.enqueue('\r\n');
controller.enqueue(`--${boundaryText}`);
controller.enqueue('\r\n');
controller.enqueue('Content-Disposition: form-data; name=Ciphertext; filename=Ciphertext; filename*=utf-8\'\'Ciphertext');
controller.enqueue('\r\n\r\n');

const reader = file.stream().getReader();

async function pushAsync() {
Expand All @@ -33,7 +41,9 @@ function uploadAsync(file) {
});
}
await pushAsync();
controller.enqueue(`\r\n--${boundaryText}--`);
controller.enqueue('\r\n');
controller.enqueue(`--${boundaryText}--`);
controller.enqueue('\r\n\r\n');

controller.close();
}
Expand Down

0 comments on commit c1e2cde

Please sign in to comment.