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
@ -95,6 +95,9 @@ export function request(options: httpModule.HttpRequestOptions): Promise<httpMod
|
||||
|
||||
if (types.isString(options.content) || options.content instanceof FormData) {
|
||||
urlRequest.HTTPBody = NSString.stringWithString(options.content.toString()).dataUsingEncoding(4);
|
||||
} else if (options.content instanceof ArrayBuffer) {
|
||||
const buffer = options.content as ArrayBuffer;
|
||||
urlRequest.HTTPBody = NSData.dataWithData(buffer as any);
|
||||
}
|
||||
|
||||
if (types.isNumber(options.timeout)) {
|
||||
@ -142,7 +145,15 @@ export function request(options: httpModule.HttpRequestOptions): Promise<httpMod
|
||||
resolve({
|
||||
content: {
|
||||
raw: data,
|
||||
toString: (encoding?: any) => NSDataToString(data, encoding),
|
||||
toArrayBuffer: () => interop.bufferFromData(data),
|
||||
toString: (encoding?: any) => {
|
||||
const str = NSDataToString(data, encoding);
|
||||
if (typeof str === "string") {
|
||||
return str;
|
||||
} else {
|
||||
throw new Error("Response content may not be converted to string");
|
||||
}
|
||||
},
|
||||
toJSON: (encoding?: any) => parseJSON(NSDataToString(data, encoding)),
|
||||
toImage: () => {
|
||||
ensureImageSource();
|
||||
|
Reference in New Issue
Block a user