GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: support ArrayBuffer/Blob for form data · nativescript-community/https@54140de

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/https
    • request.android.ts
    • request.ios.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/https/request.android.ts‎

Copy file name to clipboardExpand all lines: src/https/request.android.ts
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,19 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
519519
if (param.data instanceof okhttp3.RequestBody) {
520520
builder.addFormDataPart(param.parameterName, param.fileName, param.data);
521521
} else {
522-
builder.addFormDataPart(param.parameterName, param.fileName, okhttp3.RequestBody.create(param.data, okhttp3.MediaType.parse(param.contentType)));
522+
let nData = param.data;
523+
if (param.data instanceof ArrayBuffer) {
524+
const typedArray = new Uint8Array(param.data);
525+
const nativeBuffer = java.nio.ByteBuffer.wrap(Array.from(typedArray));
526+
nData = nativeBuffer.array();
527+
} else if (param.data instanceof Blob) {
528+
// Stolen from core xhr, not sure if we should use InternalAccessor, but it provides fast access.
529+
// @ts-ignore
530+
const typedArray = new Uint8Array(Blob.InternalAccessor.getBuffer(param.data).buffer.slice(0) as ArrayBuffer);
531+
const nativeBuffer = java.nio.ByteBuffer.wrap(Array.from(typedArray));
532+
nData = nativeBuffer.array();
533+
}
534+
builder.addFormDataPart(param.parameterName, param.fileName, okhttp3.RequestBody.create(nData, okhttp3.MediaType.parse(param.contentType)));
523535
}
524536
} else {
525537
if (typeof param.data === 'string') {
Collapse file

‎src/https/request.ios.ts‎

Copy file name to clipboardExpand all lines: src/https/request.ios.ts
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,16 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
464464
let data = param.data;
465465
if (typeof data === 'string') {
466466
data = NSString.stringWithString(data).dataUsingEncoding(NSUTF8StringEncoding);
467+
} else if (data instanceof ArrayBuffer) {
468+
const buffer = new Uint8Array(data);
469+
data = NSData.dataWithData(buffer as any);
470+
} else if (data instanceof Blob) {
471+
// Stolen from core xhr, not sure if we should use InternalAccessor, but it provides fast access.
472+
// @ts-ignore
473+
const buffer = new Uint8Array(Blob.InternalAccessor.getBuffer(data).buffer.slice(0) as ArrayBuffer);
474+
data = NSData.dataWithData(buffer as any);
467475
}
476+
468477
formData.appendPartWithFileDataNameFileNameMimeType(data, param.parameterName, param.fileName, param.contentType);
469478
}
470479
} else {

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.