mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
feat(http): better binary support & XHR support (#7707)
* feat(http): binary upload support * feat(http): better binary support & XHR support * fix: linting issue * chore: moved files from old place to the new one * chore: Updated NativeScript.api.md * feat(http): support both ByteBuffer and String Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
This commit is contained in:

committed by
Vasil Trifonov

parent
a311a922b5
commit
e293367dfc
@ -92,6 +92,7 @@ function onRequestComplete(requestId: number, result: org.nativescript.widgets.A
|
||||
callbacks.resolveCallback({
|
||||
content: {
|
||||
raw: result.raw,
|
||||
toArrayBuffer: () => Uint8Array.from(result.raw.toByteArray()).buffer,
|
||||
toString: (encoding?: HttpResponseEncoding) => {
|
||||
let str: string;
|
||||
if (encoding) {
|
||||
@ -180,7 +181,14 @@ function buildJavaOptions(options: httpModule.HttpRequestOptions) {
|
||||
javaOptions.method = options.method;
|
||||
}
|
||||
if (typeof options.content === "string" || options.content instanceof FormData) {
|
||||
javaOptions.content = options.content.toString();
|
||||
const nativeString = new java.lang.String(options.content.toString());
|
||||
const nativeBytes = nativeString.getBytes("UTF-8");
|
||||
const nativeBuffer = java.nio.ByteBuffer.wrap(nativeBytes);
|
||||
javaOptions.content = nativeBuffer;
|
||||
} else if (options.content instanceof ArrayBuffer) {
|
||||
const typedArray = new Uint8Array(options.content as ArrayBuffer);
|
||||
const nativeBuffer = java.nio.ByteBuffer.wrap(Array.from(typedArray));
|
||||
javaOptions.content = nativeBuffer;
|
||||
}
|
||||
if (typeof options.timeout === "number") {
|
||||
javaOptions.timeout = options.timeout;
|
||||
|
Reference in New Issue
Block a user