diff --git a/README-en.md b/README-en.md new file mode 100644 index 0000000000000000000000000000000000000000..ac34b0f0718d2816c4d6205932a3689f05cc48ab --- /dev/null +++ b/README-en.md @@ -0,0 +1,126 @@ +# commons-fileupload + +## Introduction + +commons-fileupload is a library used to implement file upload (including multipart upload), basic requests, and file download. Currently, the following functionalities are supported. +| Functionality| Description| Remarks| +| -------------- | ---------------------------- | -- | +| Basic requests| Supports basic operations, such as **get**, **post**, and **head**.| +| File upload| Supports multipart upload, resumable upload, and multi-file upload.| +| File download| To be supported soon.| Currently, the system does not support **expectDataType**. Therefore, file download is not supported. To download files, use the native **request** module of OpenHarmony.| + +## How to Install + +```shell +ohpm install @ohos/commons-fileupload +``` + +For details about the ohpm environment configuration, see [Installing the OpenHarmony HAR](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md). + +## Usage + +### File Upload + +1. Declare the required network permission in the **entry\src\main\module.json5** file. + +``` +{ + "module":{ + ..., + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + ] + } +} +``` + +2. Implement file upload. + +``` +import { FormData, File, FileUpload } from "@ohos/commons_fileupload" + + +aboutToAppear() { + this.fileUpload = new FileUpload({ + baseUrl: "https://musetransfer.com/", + readTimeout: 60000, + connectTimeout: 60000 + }) +} + + +const formData = new FormData(); +formData.append("key", 1);// Value of basic types can be added. Currently, strings and numbers are supported. +formData.append("myFile", File); // You can also add an object of the File type. + + +this.fileUpload.post("/api/upload", formData).then(res => { + console.log("success"); +}).catch(err => { + console.error("fail"); +}) +``` + +## Attributes and Interfaces + +### FileUpload Constructor + +| Interface | Type| Description | Mandatory| Default Value | +| :------------: | :------: | :----------: | :------: | ------- | +| baseUrl | string | Base address of the request. | No | Empty | +| connectTimeout | number | Connection timeout duration.| No | 60000 ms | +| readTimeout | number | Read timeout duration.| No | 60000 ms | + +### FileUpload APIs + +| API | Type | Description | +| :-----: | :-----------------------------------------------------------------: | :--------------: | +| post | ( configOrUrl : MyHttpRequestOptions ) : Promise | **post()** method. | +| get | ( configOrUrl : MyHttpRequestOptions ) : Promise | **get()** method. | +| head | ( configOrUrl : MyHttpRequestOptions ) : Promise | head() method. | +| options | ( configOrUrl : MyHttpRequestOptions ) : Promise | **options()** method.| +| put | ( configOrUrl : MyHttpRequestOptions ) : Promise | **put()** method. | +| delete | ( configOrUrl : MyHttpRequestOptions ) : Promise | **delete()** method. | +| trace | ( configOrUrl : MyHttpRequestOptions ) : Promise | **trace()** method. | + +### MyHttpRequestOptions + +| Interface | Type | Description | Mandatory| Default Value | +| :------------: | :-----------------------------------------: | :----------: | :------: | ------- | +| url | string | URL. | Yes | | +| extraData | string \| Object \| ArrayBuffer \| FormData | Request parameter. | No | Empty | +| header | Object | Request header. | No | Empty | +| connectTimeout | number | Connection timeout duration.| No | 60000 ms | +| readTimeout | number | Read timeout duration.| No | 60000 ms | + +## Constraints + +- DevEco Studio: 4.1 Canary (4.1.3.317), OpenHarmony SDK: API11 (4.1.0.36) + +## Directory Structure +```` +|---- ohos_commons-fileupload +| |---- entry # Sample code +| |---- library # commons-fileupload library code +| |---- src +| |---- main +| |---- ets +| |---- components +| |---- models +| |---- type +| |---- utils +| |---- index.ts +| |---- js +| |---- Index.ets # APIs exposed externally +| |---- README.md # File that describes commons-fileupload and how to use it. +```` + +## How to Contribute + +If you find any problem during the use, submit an [Issue](https://gitee.com/openharmony-sig/commons-fileupload/issues) or a [PR](https://gitee.com/openharmony-sig/commons-fileupload/pulls) to us. + +## License + +The commons-fileupload library is licensed under the terms of [Apache License 2.0](https://gitee.com/openharmony-sig/commons-fileupload/blob/master/LICENSE).