• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2020 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit BasicServicesKit
19 */
20
21/**
22 * @interface UploadResponse
23 * @syscap SystemCapability.MiscServices.Upload
24 * @since 3
25 * @deprecated since 9
26 * @useinstead ohos.request
27 */
28export interface UploadResponse {
29  /**
30   * Status code returned by the server.
31   *
32   * @syscap SystemCapability.MiscServices.Upload
33   * @since 3
34   * @deprecated since 9
35   */
36  code: number;
37
38  /**
39   * Content returned by the server.
40   * The value type is determined by the returned content.
41   *
42   * @syscap SystemCapability.MiscServices.Upload
43   * @since 3
44   * @deprecated since 9
45   */
46  data: string;
47
48  /**
49   * Headers returned by the server.
50   *
51   * @syscap SystemCapability.MiscServices.Upload
52   * @since 3
53   * @deprecated since 9
54   */
55  headers: Object;
56}
57
58/**
59 * @interface DownloadResponse
60 * @syscap SystemCapability.MiscServices.Download
61 * @since 3
62 * @deprecated since 9
63 */
64export interface DownloadResponse {
65  /**
66   * Download token, which is used to obtain the download status.
67   *
68   * @syscap SystemCapability.MiscServices.Download
69   * @since 3
70   * @deprecated since 9
71   */
72  token: string;
73}
74
75/**
76 * @interface OnDownloadCompleteResponse
77 * @syscap SystemCapability.MiscServices.Download
78 * @since 3
79 * @deprecated since 9
80 */
81export interface OnDownloadCompleteResponse {
82  /**
83   * URI of the download file.
84   *
85   * @syscap SystemCapability.MiscServices.Download
86   * @since 3
87   * @deprecated since 9
88   */
89  uri: string;
90}
91
92/**
93 * @interface RequestFile
94 * @syscap SystemCapability.MiscServices.Upload
95 * @since 3
96 * @deprecated since 9
97 */
98export interface RequestFile {
99  /**
100   * File name in the header when multipart is used.
101   *
102   * @syscap SystemCapability.MiscServices.Upload
103   * @since 3
104   * @deprecated since 9
105   */
106  filename?: string;
107
108  /**
109   * Name of a form item when multipart is used. The default value is file.
110   *
111   * @syscap SystemCapability.MiscServices.Upload
112   * @since 3
113   * @deprecated since 9
114   */
115  name?: string;
116
117  /**
118   * Local storage directory of a file.
119   *
120   * @syscap SystemCapability.MiscServices.Upload
121   * @since 3
122   * @deprecated since 9
123   */
124  uri: string;
125
126  /**
127   * Type of the file content.
128   * By default, the type is obtained based on the suffix of the file name or URI.
129   *
130   * @syscap SystemCapability.MiscServices.Upload
131   * @since 3
132   * @deprecated since 9
133   */
134  type?: string;
135}
136
137/**
138 * @interface RequestData
139 * @syscap SystemCapability.MiscServices.Upload
140 * @since 3
141 * @deprecated since 9
142 */
143export interface RequestData {
144  /**
145   * Name of the form element.
146   *
147   * @syscap SystemCapability.MiscServices.Upload
148   * @since 3
149   * @deprecated since 9
150   */
151  name: string;
152
153  /**
154   * Value of the form element.
155   *
156   * @syscap SystemCapability.MiscServices.Upload
157   * @since 3
158   * @deprecated since 9
159   */
160  value: string;
161}
162
163/**
164 * @interface UploadRequestOptions
165 * @syscap SystemCapability.MiscServices.Upload
166 * @since 3
167 * @deprecated since 9
168 */
169export interface UploadRequestOptions {
170  /**
171   * Resource URL.
172   *
173   * @syscap SystemCapability.MiscServices.Upload
174   * @since 3
175   * @deprecated since 9
176   */
177  url: string;
178
179  /**
180   * Form data in the request body.
181   *
182   * @syscap SystemCapability.MiscServices.Upload
183   * @since 3
184   * @deprecated since 9
185   */
186  data?: Array<RequestData>;
187
188  /**
189   * List of files to upload, which is submitted through multipart/form-data.
190   *
191   * @syscap SystemCapability.MiscServices.Upload
192   * @since 3
193   * @deprecated since 9
194   */
195  files: Array<RequestFile>;
196
197  /**
198   * Request header.
199   *
200   * @syscap SystemCapability.MiscServices.Upload
201   * @since 3
202   * @deprecated since 9
203   */
204  header?: Object;
205
206  /**
207   * Request methods available: POST and PUT. The default value is POST.
208   *
209   * @syscap SystemCapability.MiscServices.Upload
210   * @since 3
211   * @deprecated since 9
212   */
213  method?: string;
214
215  /**
216   * Called when the files are uploaded successfully.
217   *
218   * @syscap SystemCapability.MiscServices.Upload
219   * @since 3
220   * @deprecated since 9
221   */
222  success?: (data: UploadResponse) => void;
223
224  /**
225   * Called when uploading fails.
226   *
227   * @syscap SystemCapability.MiscServices.Upload
228   * @since 3
229   * @deprecated since 9
230   */
231  fail?: (data: any, code: number) => void;
232
233  /**
234   * Called when the execution is completed.
235   *
236   * @syscap SystemCapability.MiscServices.Upload
237   * @since 3
238   * @deprecated since 9
239   */
240  complete?: () => void;
241}
242
243/**
244 * @interface DownloadRequestOptions
245 * @syscap SystemCapability.MiscServices.Download
246 * @since 3
247 * @deprecated since 9
248 */
249export interface DownloadRequestOptions {
250  /**
251   * Resource URL.
252   *
253   * @syscap SystemCapability.MiscServices.Download
254   * @since 3
255   * @deprecated since 9
256   */
257  url: string;
258
259  /**
260   * Name of the file to downloaded.
261   * The value is obtained from the current request or resource URL by default.
262   *
263   * @syscap SystemCapability.MiscServices.Download
264   * @since 3
265   * @deprecated since 9
266   */
267  filename?: string;
268
269  /**
270   * Request header.
271   *
272   * @syscap SystemCapability.MiscServices.Download
273   * @since 3
274   * @deprecated since 9
275   */
276  header?: string;
277
278  /**
279   * Download description.
280   * The default value is the file name.
281   *
282   * @syscap SystemCapability.MiscServices.Download
283   * @since 3
284   * @deprecated since 9
285   */
286  description?: string;
287
288  /**
289   * Called when the files are successfully downloaded.
290   *
291   * @syscap SystemCapability.MiscServices.Download
292   * @since 3
293   * @deprecated since 9
294   */
295  success?: (data: DownloadResponse) => void;
296
297  /**
298   * Called when downloading fails.
299   *
300   * @syscap SystemCapability.MiscServices.Download
301   * @since 3
302   * @deprecated since 9
303   */
304  fail?: (data: any, code: number) => void;
305
306  /**
307   * Called when the execution is completed.
308   *
309   * @syscap SystemCapability.MiscServices.Download
310   * @since 3
311   * @deprecated since 9
312   */
313  complete?: () => void;
314}
315
316/**
317 * @interface OnDownloadCompleteOptions
318 * @syscap SystemCapability.MiscServices.Download
319 * @since 3
320 * @deprecated since 9
321 */
322export interface OnDownloadCompleteOptions {
323  /**
324   * Token of the result returned by the download function.
325   *
326   * @syscap SystemCapability.MiscServices.Download
327   * @since 3
328   * @deprecated since 9
329   */
330  token: string;
331
332  /**
333   * Called when the downloads are successfully obtained
334   *
335   * @syscap SystemCapability.MiscServices.Download
336   * @since 3
337   * @deprecated since 9
338   */
339  success?: (data: OnDownloadCompleteResponse) => void;
340
341  /**
342   * Called when the downloads fail to be obtained.
343   *
344   * @syscap SystemCapability.MiscServices.Download
345   * @since 3
346   * @deprecated since 9
347   */
348  fail?: (data: any, code: number) => void;
349
350  /**
351   * Called when the execution is completed.
352   *
353   * @syscap SystemCapability.MiscServices.Download
354   * @since 3
355   * @deprecated since 9
356   */
357  complete?: () => void;
358}
359
360/**
361 * @since 3
362 * @deprecated since 9
363 */
364export default class Request {
365  /**
366   * Upload files.
367   *
368   * @param { UploadRequestOptions } options Options.
369   * @syscap SystemCapability.MiscServices.Upload
370   * @since 3
371   * @deprecated since 9
372   */
373  static upload(options: UploadRequestOptions): void;
374
375  /**
376   * This API is used to download files.
377   *
378   * @param { DownloadRequestOptions } options Options.
379   * @syscap SystemCapability.MiscServices.Download
380   * @since 3
381   * @deprecated since 9
382   */
383  static download(options: DownloadRequestOptions): void;
384
385  /**
386   * Listens to download task status.
387   *
388   * @param { OnDownloadCompleteOptions } options Options.
389   * @syscap SystemCapability.MiscServices.Download
390   * @since 3
391   * @deprecated since 9
392   */
393  static onDownloadComplete(options: OnDownloadCompleteOptions): void;
394}
395