• Stars
    star
    148
  • Rank 242,543 (Top 5 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 6 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Alibaba Cloud OSS SDK for React Native

README of Chinese

Introduction

This document mainly describes how to install and use the OSS React Native SDK. This document assumes that you have already activated the Alibaba Cloud OSS service and created an AccessKeyID and an AccessKeySecret. In the document, ID refers to the AccessKeyID and KEY indicates the AccessKeySecret. If you have not yet activated or do not know about the OSS service, log on to the OSS Product Homepage for more help.

Lanaguage

  • JavaScript、JAVA、Objective-C

Environment requirements

  • Android 2.3 or above
  • IOS 8.0 or above
  • You must have registered an Alibaba Cloud account with the OSS activated.
  • Node 8.0 or above
  • React Native 0.44.0 or above

Table of Contents

Installation

NOTE: THIS PACKAGE IS NOW BUILT FOR REACT NATIVE 0.40 OR GREATER

  • npm
npm install aliyun-oss-react-native --save
  • yarn
yarn install aliyun-oss-react-native --save

Automatic Installation

run react-native link in the react native project

react-native link aliyun-oss-react-native

Note:for suppport IPv6-Only networkd,you need to require :

1. libresolv.tbd
2. CoreTelephony.framework
3. SystemConfiguration.framework

Manual Installation

iOS

  • CocoaPods
pod 'aliyun-oss-react-native', :path => '../node_modules/aliyun-oss-react-native'
  • no CocoaPods
  1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...> Go to node_modulesaliyun-oss-react-nativeios ➜ select RNAliyunOSS.xcodeproj
  2. Add libRNAliyunOSS.a to Build Phases -> Link Binary With Libraries
  3. In XCode, in the project navigator, right click FrameworksAdd Files to [your project's name]. Go to node_modulesaliyun-oss-react-nativeAliyunSDK. Add AliyunOSSiOS.framework, and select Copy items if needed in the pop-up box.

Android

  1. Add the following lines to android/settings.gradle:
include ':react-native-react-sdk'
project(':react-native-react-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/aliyun-oss-rn-sdk/android')
  1. Add the compile line to the dependencies in android/app/build.gradle:
dependencies {
  compile project(':aliyun-oss-react-native')
}
  1. Add the required permissions in AndroidManifest.xml:
   <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
   <uses-permission android:name="android.permission.CAMERA" />
  1. Add the import and link the package in MainApplication.java:
import com.reactlibrary.RNAliyunOssPackage;

 public class MainApplication extends Application implements ReactApplication {
  @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new RNAliyunOssPackage()
    );
  }
}

Usage

Now ,all the API returns Promise Object exception init OSS Client API and enableDevMode API,so you can use ES6 async await or promise().then(/**/).catch(/**/),we take asyncUpload interface as an example.

  • step-1:import AliyunOSS
import AliyunOSS from 'aliyun-oss-react-native'
  • step-2:open debug mode (optional)
AliyunOSS.enableDevMode();
  • step-3:init configuration(optional)
const configuration = {
   maxRetryCount: 3,
   timeoutIntervalForRequest: 30,
   timeoutIntervalForResource: 24 * 60 * 60
};
  • step-4:init OSS Client,we provide 4 ways to init OSS Client. here we recommend initWithServerSTS
const endpoint = "xxxx.aliyuncs.com"

AliyunOSS.initWithServerSTS("/***http://ip:port/****/",endPoint, configuration)

Note:We provide auth server with node shell in Script folder,you can run command link this.

  1. npm istall
  2. modify accessKeyId and accessKeySecret in the config.js
  3. node index.js,port is defalut 9000,The auth server is like (http|https)://ip.com:9000/
  • step-5:
    <!-- note:filepath must start with file:/// -->
    AliyunOSS.asyncUpload(bucketname, objectkey, filePath).then( (res) => {
        <!-- you can see the log with React Native debugg tools or XCode 、Android studio console -->
        console.log(res)
    }).catch((error)=>{
        console.log(error)
    })
    <!-- addEventlistener uploadPross-->
   const downloadProgress = p => console.log(p.currentSize / p.totalSize);
   AliyuOSS.addEventListener('uploadProgress', downloadProgress);

api

This section describes the APIs that are currently implemented and partially supported by the React Native SDK. These APIs mainly cover log management, bucket management, object management, authorization, file upload, and download. Follow-up to improve the relevant API and BUG repair. API list is as follows

API Android iOS
enableDevMode Y Y
initWithPlainTextAccessKey Y Y
initWithSigner Y Y
initWithSecurityToken Y Y
initWithServerSTS Y Y
asyncUpload Y Y
initMultipartUpload Y Y
multipartUpload Y Y
listParts Y Y
abortMultipartUpload Y Y
asyncDownload Y Y
asyncCreateBucket Y Y
asyncGetBucketACL Y Y
asyncListBuckets Y Y
asyncDeleteBucket Y Y
asyncHeadObject Y Y
asyncListObjects Y Y
doesObjectExist Y Y
doesObjectExist Y Y
asyncDeleteObject Y Y

enableDevMode

open dev log,please refer to the code

AliyunOSS.enableDevMode()

initWithPlainTextAccessKey

init auth client with accessKeyId and accessKeySecret,please refer to the code.you can use ,but we do not suggest use it。

const endPoint = "XXX"
const configuration = {
    maxRetryCount: 3,
    timeoutIntervalForRequest: 30,
    timeoutIntervalForResource: 24 * 60 * 60
 };
AliyunOSS.initWithPlainTextAccessKey(accessKey, secretKey, endPoint, configuration);

initWithSigner

init auth client the sign

AliyunOSS.initWithSigner(signature, accessKey, endPoint, configuration);

initWithSecurityToken

init client with SecurityToken

AliyunOSS.initWithSecurityToken(SecurityToken, accessKeyId, accessKeySecret, endPoint, configuration);


### initWithServerSTS

init auth client with local auth server

```javascript
AliyunOSS.initWithServerSTS(/*local auth server*/, endPoint, configuration);

asyncUpload

AliyunOSS.asyncUpload(bucketname, objectKey, filepath).then().catch()

asyncAppendObject

asyncResumableUpload

initMultipartUpload

 AliyunOSS.initMultipartUpload(bucketname,objectkey).then((e) => {
      //e is uploadId
      console.log(e)
    }).catch((error) => {
      console.log(error)
 })

multipartUpload

//uploadId is  the value When call initMultipartUpload ,success callback return
AliyunOSS.multipartUpload(multipartBucket,mulitipartObjectKey,uploadId,filepath).then((res)=>{
    Alert.alert("success");
  }).catch((e) => {
    Alert.alert("fail");
  })

listParts

AliyunOSS.listParts(multipartBucket,multipartObjectKey,upoadId).then((e)=>{
    Alert.alert("onListParts"+e)
  }).catch((e)=>{
    Alert.alert("onListPartsError")
 })

abortMultipartUpload

 AliyunOSS.abortMultipartUpload(multipartBucket,multipartBucket,uploadId).then((e)=>{
    Alert.alert("abort success");
  }).catch((e)=>{
    Alert.alert("abort fali");
  })

asyncDownload

 // xxx is the image process option
 AliyunOSS.asyncDownload(bucketname,objectkey,{"x-oss-process":'xxxx'}).then((e) => {
    console.log(e)
  }).catch((e)=>{
    console.log(e)
  })

asyncCreateBucket

 AliyunOSS.asyncCreateBucket('tyluoluo','private','oss-cn-zhangjiakou').then((e) => {
    console.log(e)
  }).catch((e)=>{
     console.log(e)
  })

asyncGetBucketACL

 AliyunOSS.asyncGetBucketACL('luozhang002').then((e) => {
    console.log(e)
  }).catch((e)=>{
    console.log(e)
  })

asyncListBuckets

AliyunOSS.asyncListBuckets().then((e) => {
    console.log(e)
  }).catch((e) => {
    console.log(e)
  })

asyncDeleteBucket

 AliyunOSS.asyncDeleteBucket("tyluoluo").then((e) => {
    console.log(e)
  }).catch((e) => {
    console.log(e)
  })

asyncHeadObject

 AliyunOSS.asyncHeadObject('luozhang002','yanxing').then((e)=>{
    console.log(e)
  }).catch((e)=> {
     console.log(e)
 })

asyncListObjects

list objects in some conditions

parameters:

  • name {String} bucket name
  • options {Object}
    • [delimiter] {String}
    • [prefix] {String} search buckets using prefix key
    • [marker] {String} search start from marker, including marker key
    • [max-keys] {String|Number} max buckets, default is 100, limit to 1000
 AliyunOSS.asyncListObjects('luozhang002', {
    prefix:'xxxx'
}).then((e)=>{
    console.log(e)
  }).catch((e)=>{
     console.log(e)
  })

doesObjectExist

 AliyunOSS.doesObjectExist('luozhang001','xx.png').then( (e) => {
    console.log(e)
  }).catch((e) => {
    console.log(e)
  })

asyncCopyObject

 AliyunOSS.asyncCopyObject('luozhang001',"2.png","luozhang002","sbsbsb").then( (e) => {
    console.log(e)
  }).catch((e)=>{
    console.log("xxxx")
    console.log(e)
  })

asyncDeleteObject

 AliyunOSS.asyncDeleteObject('luozhang001','2.png').then((e)=>{
    Alert.alert(e)
  }).catch((e)=>{
    console.log(e)
  })

DEMO

In the repository, we prodive RN SDK DEMO in the Example folder including andriod and ios,Example/android provide the android demo;Example/iOS provide the ios demo.Welcome to join us, how to run the Example ?

  • step-1:clone the project and install some dependencies
1. git clone https://github.com/aliyun/aliyun-oss-react-native.git
2. cd Example
3. npm install
  • step-2:start local auth server and modify the URL in initWithServerSTS function of Example/App.js,Server address must begin with ip,of cource you can refer to the scrpts folder we provied.defalut port is 9000
1. cd script/sts-app-server-node
2. node index.js
  • step-3:run the project
  1. npm run start
  2. open Example/android ,compile and run with Android Studio.The effect is as follows

  1. open Example/NativeAddRN ,compile and run with XCode,The effect is as follows

F&Q

  • Due to the complexity of React Native's own environment on the iOS side,it ofen occur differrent errors, please go to stackoverflow
  • close proxy
  • Sometimes,you can not see the ui in the debugging mode of the Android Studio Envrionment, please delete the Build folder under the project file and then recompile

Join

Now, React Native SDK is in the initial stage. When the developers use React Native API, any problem can be raised to the official warehouse for issue or PR. We will deal with it in time. Wecome much more developers to join us to serve customers and developers that who use aliyun storage services To better serve customers and developers who use aliyun storage services.You can refer to the following documentation.

License

  • MIT

Contact us

Future

in the future, Continuously optimizing code documentation、add interfaces 、fix bugs, etc.

Documentation

enhancement

More Repositories

1

oss-browser

OSS Browser 提供类似windows资源管理器功能。用户可以很方便的浏览文件,上传下载文件,支持断点续传等。
JavaScript
3,111
star
2

aliyun-openapi-java-sdk

Alibaba Cloud SDK for Java
Java
1,379
star
3

aliyun-oss-java-sdk

Aliyun OSS SDK for Java
Java
1,195
star
4

alibaba-cloud-sdk-go

Alibaba Cloud SDK for Go
Go
1,104
star
5

alicloud-android-demo

Java
982
star
6

aliyun-openapi-python-sdk

Alibaba Cloud SDK for Python
Python
980
star
7

aliyun-oss-php-sdk

Aliyun OSS SDK for PHP
PHP
975
star
8

aliyun-oss-go-sdk

Aliyun OSS SDK for Go
Go
933
star
9

aliyun-oss-python-sdk

Aliyun OSS SDK for Python
Python
907
star
10

darabonba

Darabonba 是一种用于 OpenAPI 的 DSL 语言,可以用来生成多语言的 SDK、Code Sample、Test Case 等代码
JavaScript
894
star
11

alibabacloud-alfa

阿里云微前端解决方案
TypeScript
838
star
12

aliyun-oss-android-sdk

Android SDK for aliyun object storage service
Java
793
star
13

aliyun-cli

Alibaba Cloud CLI
Go
770
star
14

ossfs

Export s3fs for aliyun oss.
C++
718
star
15

aliyun-openapi-php-sdk

[Abandoned] Open API SDK for PHP developers
PHP
605
star
16

terraform-provider-alicloud

Terraform AliCloud provider
Go
573
star
17

aliyun-openapi-net-sdk

Alibaba Cloud SDK for .NET
C#
534
star
18

rds_dbsync

围绕 PostgreSQL Greenplum ,实现易用的数据的互迁功能项目
C
528
star
19

openapi-sdk-php

Alibaba Cloud SDK for PHP
PHP
501
star
20

iotkit-embedded

高速镜像: https://code.aliyun.com/linkkit/c-sdk
C
492
star
21

aliyun-oss-ios-sdk

iOS SDK for aliyun object storage service
Objective-C
450
star
22

alicloud-ios-demo

Demos for AMS iOS SDKs
Objective-C
427
star
23

ossutil

A user friendly command line tool to access AliCloud OSS.
Go
427
star
24

aliyun-odps-python-sdk

ODPS Python SDK and data analysis framework
Python
407
star
25

api-gateway-demo-sign-java

aliyun api gateway request signature demo by java
Java
371
star
26

alibabacloud-microservice-demo

An Alibaba Cloud native microservice demo powered by Apache Dubbo and Spring Cloud Alibaba
Java
368
star
27

aliyun-oss-csharp-sdk

Aliyun OSS SDK for C#
C#
360
star
28

NeWCRFs

Python
344
star
29

surftrace

surftrace is a tool that allows you to surf the linux kernel
Python
332
star
30

conditional-lane-detection

Python
328
star
31

aliyun-log-jaeger

Go
294
star
32

tablestore-examples

Example code for aliyun tablestore.
Java
236
star
33

tablestore-timeline

TableStore-Timeline Model for Social scene
Java
236
star
34

coolbpf

C
222
star
35

openapi-sdk-php-client

Official repository of the Alibaba Cloud Client for PHP
PHP
214
star
36

aliyun-log-c-sdk

Aliyun LOG Producer for C/C++
C
212
star
37

aliyun-log-logback-appender

Java
176
star
38

openapi-core-nodejs-sdk

OpenAPI POP core SDK for Node.js
JavaScript
175
star
39

aliyun-log-android-sdk

Java
174
star
40

alibabacloud-jindodata

alibabacloud-jindodata
170
star
41

aliyun-emapreduce-datasources

Extended datasource support for Spark/Hadoop on Aliyun E-MapReduce.
Scala
168
star
42

aliyun-log-python-sdk

Use python to manage, produce and consume data with Aliyun Log Service.
Python
161
star
43

aliyun-apsaradb-hbase-demo

C++
147
star
44

data-mapping-component

A React Component which focus on Data-Mapping & Table-Field-Mapping.(基于React的数据/表字段映射组件)
JavaScript
146
star
45

aliyun-oss-c-sdk

Aliyun OSS SDK for C
C
144
star
46

django-oss-storage

Django storage backends for AliCloud OSS.
Python
142
star
47

aliyun-oss-ruby-sdk

Aliyun OSS SDK for Ruby
Ruby
138
star
48

ram-policy-editor

AliCloud RAM Policy Editor for OSS
JavaScript
135
star
49

serverless-aliyun-function-compute

Serverless Alibaba Cloud Function Compute Plugin – Add Alibaba Cloud Function Compute support to the Serverless Framework
JavaScript
133
star
50

react-visual-modeling

A DAG React Component for visualization modeling, suitable for UML, database modeling, data warehouse construction.(一个基于React的数据可视化建模的DAG图,适用于UML,数据库建模,数据仓库建设等业务)
JavaScript
132
star
51

alibabacloud-console-components

阿里云企业云管理平台 UI 组件库
TypeScript
131
star
52

fc-nodejs-sdk

The Node.js SDK of FunctionCompute.
JavaScript
130
star
53

aliyun-log-java-sdk

Java
130
star
54

aliyun-cms-grafana

JavaScript
127
star
55

aliyun-log-java-producer

Aliyun LOG Java Producer
Java
124
star
56

alibabacloud-quantization-networks

alibabacloud-quantization-networks
Python
122
star
57

aliyun-emapreduce-demo

Java
121
star
58

aliyun-odps-jdbc

JDBC Driver for ODPS
Java
118
star
59

alicloud-ams-demo

C#
117
star
60

aliyun-maxcompute-data-collectors

Java
113
star
61

alibabacloud-iot-device-sdk

alibaba cloud for iot device javascript SDK , connect with linkplatform , run at node/broswer/winxin min program /ali min program. 阿里云IoT物联网平台javascript版本sdk,可以运行在node/broswer/winxin min program /ali min program. 阿里云IoT物联网平台javascript版本sdk,可以运行在node/broswer/winxin min program /ali min program
JavaScript
110
star
62

api-gateway-nodejs-sdk

The API Gateway SDK for Node.js
JavaScript
104
star
63

MaxCompute-Spark

MaxCompute spark demo for building a runnable application.
Scala
104
star
64

gm-jsse

开源国密通信纯 Java JSSE 实现
Java
95
star
65

cloud-design

阿里云前端组件库,由专有云&公有云前端团队共建
CSS
95
star
66

aliyun-openapi-cpp-sdk

Alibaba Cloud SDK for C++
C++
90
star
67

aliyun-odps-console

ODPS Console Source Code.
Java
90
star
68

aliyun-tablestore-nodejs-sdk

Aliyun TableStore(原OTS) SDK for Node.js
JavaScript
88
star
69

aliyun-odps-java-sdk

ODPS SDK for Java Developers
Java
85
star
70

iotx-api-demo

PHP
83
star
71

aliyun-log-ios-sdk

Aliyun LOG iOS SDK
Swift
82
star
72

algorithm-base

让算法工程化更简单
Python
81
star
73

aliyun-openapi-nodejs-sdk

Alibaba Cloud SDK for Node.js
JavaScript
80
star
74

plugsched

Live upgrade Linux kernel scheduler subsystem
Python
77
star
75

DCT-Mask

Python
76
star
76

alibabacloud-redis-training-demo

Java
76
star
77

aliyun-oss-php-sdk-laravel

A Laravel service provider for the AliCloud OSS SDK for PHP
PHP
75
star
78

aliyun-tablestore-go-sdk

TableStore SDK for Golang
Go
75
star
79

fc-docker

Dockerfiles for local building or running function of FC
Dockerfile
74
star
80

aliyun-specs

Aliyun Mobile Service CocoaPods specs.
Ruby
74
star
81

dro-sfm

Python
74
star
82

packagist-mirror

Alibaba Cloud Packagist Mirror
Go
73
star
83

alibabacloud-console-design

阿里云管平台研发解决方案
TypeScript
73
star
84

elasticsearch-repository-oss

Java
72
star
85

alibabacloud-sdk

Tea
72
star
86

react-monitor-dag

A React-based operation/monitoring DAG diagram.(基于React的运维/监控DAG图)
JavaScript
68
star
87

aliyun-log-php-sdk

PHP
66
star
88

aliyun-tsdb-java-sdk

Aliyun TSDB SDK for Java
Java
64
star
89

aliyun-log-log4j-appender

aliyun-log-log4j-appender
Java
63
star
90

aliyun_assist_client

Aliyun Assist Client 阿里云 云助手
Go
62
star
91

fc-java-sdk

The Java SDK of FunctionCompute.
Java
61
star
92

alibabacloud-hologres-connectors

alibabacloud-hologres-connectors
Java
61
star
93

oss-ftp

The ftp proxy for Aliyun OSS.
Python
61
star
94

aliyun-log-cli

Command Line Interface for Aliyun Log Service
Python
59
star
95

csb-sdk

The CSB-SDK is a client-side invocation SDK for HTTP or Web Service API opened by the CSB (Cloud Service Bus) product. It is responsible for invoking the open API and signing the request information.
Java
58
star
96

aliyun-log-flink-connector

flink log connector
Java
58
star
97

ossimport

Data migration tool
57
star
98

oss-emulator

OSS Emulator
Ruby
57
star
99

fc-python-sdk

The python sdk of Aliyun FunctionCompute
Python
55
star
100

aliyun-log-dotnetcore-sdk

C#
54
star