Skip to content

Commit c1affb9

Browse files
committed
fix file upload android
1 parent e25bf34 commit c1affb9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

templates/react-native/src/services/template.ts.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { {{ spec.title | caseUcfirst}}Exception, Client } from '../client';
33
import type { Models } from '../models';
44
import type { UploadProgress, Payload } from '../client';
55
import * as FileSystem from 'expo-file-system';
6+
import * as Device from 'expo-device';
67

78
{% set added = [] %}
89
{% for method in service.methods %}
@@ -144,8 +145,13 @@ export class {{ service.name | caseUcfirst }} extends Service {
144145
position: offset,
145146
length: Service.CHUNK_SIZE
146147
});
148+
var path = `data:${{'{'}}{{ parameter.name | caseCamel | escapeKeyword }}.type{{'}'}};base64,${{'{'}}chunk{{'}'}}`;
149+
if (Device.osName === 'Android') {
150+
path = FileSystem.cacheDirectory + '/tmp_chunk';
151+
await FileSystem.writeAsStringAsync(path, chunk, {encoding: FileSystem.EncodingType.Base64});
152+
}
147153

148-
payload['{{ parameter.name }}'] = {{ '{' }} uri: `data:${{'{'}}{{ parameter.name | caseCamel | escapeKeyword }}.type{{'}'}};base64,${{'{'}}chunk{{'}'}}`, name: {{ parameter.name | caseCamel | escapeKeyword }}.name, type: {{ parameter.name | caseCamel | escapeKeyword }}.type {{ '}' }};
154+
payload['{{ parameter.name }}'] = {{ '{' }} uri: path, name: {{ parameter.name | caseCamel | escapeKeyword }}.name, type: {{ parameter.name | caseCamel | escapeKeyword }}.type {{ '}' }};
149155

150156
response = await this.client.call('{{ method.method | caseLower }}', uri, apiHeaders, payload);
151157

0 commit comments

Comments
 (0)