diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp index 9e1815511a..5f9a1bce82 100644 --- a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp @@ -76,7 +76,7 @@ ErrorOr Blob::process_blob_parts(Vector const& blob_parts) }, // 3. If element is a Blob, append the bytes it represents to bytes. [&](NonnullRefPtr const& blob) -> ErrorOr { - return bytes.try_append(blob->m_byte_buffer.bytes()); + return bytes.try_append(blob->bytes()); })); } return bytes; diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.h b/Userland/Libraries/LibWeb/FileAPI/Blob.h index 0035f243f5..4947323544 100644 --- a/Userland/Libraries/LibWeb/FileAPI/Blob.h +++ b/Userland/Libraries/LibWeb/FileAPI/Blob.h @@ -48,14 +48,14 @@ public: virtual JS::Object* create_wrapper(JS::GlobalObject&); + ReadonlyBytes bytes() const { return m_byte_buffer.bytes(); } + private: Blob() = default; static ErrorOr process_blob_parts(Vector const& blob_parts); ByteBuffer m_byte_buffer {}; String m_type {}; - - friend class XHR::XMLHttpRequest; }; } diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 9bd319bd1c..e16b9e756d 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -475,10 +475,19 @@ DOM::ExceptionOr XMLHttpRequest::send(Optional bod auto request = LoadRequest::create_for_url_on_page(request_url, m_window->page()); request.set_method(m_method); if (body_with_type.has_value()) { - body_with_type->body.source().visit( - [&](ByteBuffer const& buffer) { request.set_body(buffer); }, - [&](NonnullRefPtr const& blob) { request.set_body(blob->m_byte_buffer); }, - [](auto&) {}); + TRY_OR_RETURN_OOM(body_with_type->body.source().visit( + [&](ByteBuffer const& buffer) -> ErrorOr { + request.set_body(buffer); + return {}; + }, + [&](NonnullRefPtr const& blob) -> ErrorOr { + auto byte_buffer = TRY(ByteBuffer::copy(blob->bytes())); + request.set_body(byte_buffer); + return {}; + }, + [](auto&) -> ErrorOr { + return {}; + })); if (body_with_type->type.has_value()) request.set_header("Content-Type", String { body_with_type->type->span() }); }