├── android
├── libs
│ ├── okio-1.10.0.jar
│ └── okhttp-3.4.1.jar
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── dskj
│ │ └── dscj
│ │ └── aliyunoss
│ │ ├── aliyunossPackage.java
│ │ └── aliyunossModule.java
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── build.gradle
├── gradlew.bat
└── gradlew
├── ios
├── AliyunOSSSDK
│ ├── AliyunOSSiOS
│ ├── OSSService.h
│ ├── OSSBolts.h
│ ├── OSSCancellationTokenRegistration.h
│ ├── OSSLog.h
│ ├── OSSCancellationToken.h
│ ├── OSSUtil.h
│ ├── OSSExecutor.h
│ ├── OSSCancellationTokenSource.h
│ ├── OSSTaskCompletionSource.h
│ ├── OSSCompat.h
│ ├── OSSDefine.h
│ ├── OSSXMLDictionary.h
│ ├── OSSNetworking.h
│ ├── OSSClient.h
│ ├── OSSTask.h
│ └── OSSModel.h
├── RCTAliyunOSS
│ ├── RCTAliyunOSS.h
│ └── RCTAliyunOSS.m
└── RCTAliyunOSS.xcodeproj
│ └── project.pbxproj
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── index.js
└── package.json
/android/libs/okio-1.10.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lesonli/react-native-aliyun-oss/HEAD/android/libs/okio-1.10.0.jar
--------------------------------------------------------------------------------
/android/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AliyunOSS
3 |
4 |
--------------------------------------------------------------------------------
/android/libs/okhttp-3.4.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lesonli/react-native-aliyun-oss/HEAD/android/libs/okhttp-3.4.1.jar
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/AliyunOSSiOS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lesonli/react-native-aliyun-oss/HEAD/ios/AliyunOSSSDK/AliyunOSSiOS
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lesonli/react-native-aliyun-oss/HEAD/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/ios/RCTAliyunOSS/RCTAliyunOSS.h:
--------------------------------------------------------------------------------
1 | //
2 | // RCTAliyunOSS.h
3 | // RCTAliyunOSS
4 | //
5 | // Created by 李京生 on 2016/10/26.
6 | // Copyright © 2016年 lesonli. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface RCTAliyunOSS : RCTEventEmitter
13 |
14 | @end
15 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSService.h:
--------------------------------------------------------------------------------
1 | //
2 | // OSSService.h
3 | // oss_ios_sdk
4 | //
5 | // Created by zhouzhuo on 8/20/15.
6 | // Copyright (c) 2015 aliyun.com. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #define OSS_IOS_SDK_VERSION 2.5.2
12 |
13 | #import "OSSDefine.h"
14 | #import "OSSNetworking.h"
15 | #import "OSSClient.h"
16 | #import "OSSModel.h"
17 | #import "OSSUtil.h"
18 | #import "OSSLog.h"
19 |
20 | #import "OSSBolts.h"
21 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | }
14 |
15 | dependencies {
16 | compile 'com.android.support:appcompat-v7:23.0.1'
17 | compile 'com.facebook.react:react-native:+'
18 | compile 'com.aliyun.dpa:oss-android-sdk:2.4.2'
19 | }
20 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 |
3 | # typings
4 | #
5 | typings
6 | typings.json
7 | # OSX
8 | #
9 | .DS_Store
10 |
11 | # Xcode
12 | #
13 | build/
14 | *.pbxuser
15 | !default.pbxuser
16 | *.mode1v3
17 | !default.mode1v3
18 | *.mode2v3
19 | !default.mode2v3
20 | *.perspectivev3
21 | !default.perspectivev3
22 | xcuserdata
23 | *.xccheckout
24 | *.moved-aside
25 | DerivedData
26 | *.hmap
27 | *.ipa
28 | *.xcuserstate
29 | project.xcworkspace
30 |
31 | # Android/IJ
32 | #
33 | *.iml
34 | .idea
35 | .gradle
36 | local.properties
37 |
38 | # node.js
39 | #
40 | node_modules/
41 | npm-debug.log
42 |
43 | # BUCK
44 | buck-out/
45 | \.buckd/
46 | android/app/libs
47 | android/keystores/debug.keystore
48 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .vscode
2 |
3 | # typings
4 | #
5 | typings
6 | typings.json
7 | # OSX
8 | #
9 | .DS_Store
10 |
11 | # Xcode
12 | #
13 | build/
14 | *.pbxuser
15 | !default.pbxuser
16 | *.mode1v3
17 | !default.mode1v3
18 | *.mode2v3
19 | !default.mode2v3
20 | *.perspectivev3
21 | !default.perspectivev3
22 | xcuserdata
23 | *.xccheckout
24 | *.moved-aside
25 | DerivedData
26 | *.hmap
27 | *.ipa
28 | *.xcuserstate
29 | project.xcworkspace
30 |
31 | # Android/IJ
32 | #
33 | *.iml
34 | .idea
35 | .gradle
36 | local.properties
37 |
38 | # node.js
39 | #
40 | node_modules/
41 | npm-debug.log
42 |
43 | # BUCK
44 | buck-out/
45 | \.buckd/
46 | android/app/libs
47 | android/keystores/debug.keystore
48 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSBolts.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 |
11 | #import "OSSCancellationToken.h"
12 | #import "OSSCancellationTokenRegistration.h"
13 | #import "OSSCancellationTokenSource.h"
14 | #import "OSSExecutor.h"
15 | #import "OSSTask.h"
16 | #import "OSSTaskCompletionSource.h"
17 |
18 |
19 | NS_ASSUME_NONNULL_BEGIN
20 |
21 | /**
22 | A string containing the version of the Bolts Framework used by the current application.
23 | */
24 | extern NSString *const OSSBoltsFrameworkVersionString;
25 |
26 | NS_ASSUME_NONNULL_END
27 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSCancellationTokenRegistration.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 |
11 | #import
12 |
13 | NS_ASSUME_NONNULL_BEGIN
14 |
15 | /*!
16 | Represents the registration of a cancellation observer with a cancellation token.
17 | Can be used to unregister the observer at a later time.
18 | */
19 | @interface OSSCancellationTokenRegistration : NSObject
20 |
21 | /*!
22 | Removes the cancellation observer registered with the token
23 | and releases all resources associated with this registration.
24 | */
25 | - (void)dispose;
26 |
27 | @end
28 |
29 | NS_ASSUME_NONNULL_END
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 lotosbin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/android/src/main/java/com/dskj/dscj/aliyunoss/aliyunossPackage.java:
--------------------------------------------------------------------------------
1 | package com.dskj.dscj.aliyunoss;
2 |
3 | import com.facebook.react.ReactPackage;
4 | import com.facebook.react.bridge.JavaScriptModule;
5 | import com.facebook.react.bridge.NativeModule;
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.react.uimanager.ViewManager;
8 |
9 | import java.util.Arrays;
10 | import java.util.Collections;
11 | import java.util.List;
12 | /**
13 | * Created by lesonli on 2016/10/31.
14 | */
15 |
16 | public class aliyunossPackage implements ReactPackage {
17 | @Override
18 | public List createNativeModules(ReactApplicationContext reactContext) {
19 | return Arrays.asList(
20 | new aliyunossModule(reactContext)
21 | );
22 | }
23 |
24 | // Deprecated RN 0.47
25 | public List> createJSModules() {
26 | return Collections.emptyList();
27 | }
28 |
29 | @Override
30 | public List createViewManagers(ReactApplicationContext reactContext) {
31 | return Arrays.asList(
32 | );
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSLog.h:
--------------------------------------------------------------------------------
1 | //
2 | // OSSLog.h
3 | // oss_ios_sdk
4 | //
5 | // Created by zhouzhuo on 8/16/15.
6 | // Copyright (c) 2015 aliyun.com. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | // colorful log configuration
12 | // see https://github.com/robbiehanson/XcodeColors
13 |
14 | #define XCODE_COLORS_ESCAPE @"\033["
15 |
16 | #define XCODE_COLORS_RESET_FG XCODE_COLORS_ESCAPE @"fg;" // Clear any foreground color
17 | #define XCODE_COLORS_RESET_BG XCODE_COLORS_ESCAPE @"bg;" // Clear any background color
18 | #define XCODE_COLORS_RESET XCODE_COLORS_ESCAPE @";" // Clear any foreground or background color
19 |
20 | #define OSSLogVerbose(frmt, ...)\
21 | if ([OSSLog isLogEnable]) {\
22 | NSLog(@"[Verbose]: %@", [NSString stringWithFormat:(frmt), ##__VA_ARGS__]);\
23 | }
24 |
25 | #define OSSLogDebug(frmt, ...)\
26 | if ([OSSLog isLogEnable]) {\
27 | NSLog(@"[Debug]: %@", [NSString stringWithFormat:(frmt), ##__VA_ARGS__]);\
28 | }
29 |
30 | #define OSSLogError(frmt, ...)\
31 | if ([OSSLog isLogEnable]) {\
32 | NSLog(@"[Error]: %@", [NSString stringWithFormat:(frmt), ##__VA_ARGS__]);\
33 | }
34 | static BOOL isEnable;
35 |
36 | @interface OSSLog : NSObject
37 | + (void)enableLog;
38 | + (void)disableLog;
39 | + (BOOL)isLogEnable;
40 | @end
41 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSCancellationToken.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 |
11 | #import
12 |
13 | #import "OSSCancellationTokenRegistration.h"
14 |
15 | NS_ASSUME_NONNULL_BEGIN
16 |
17 | /*!
18 | A block that will be called when a token is cancelled.
19 | */
20 | typedef void(^OSSCancellationBlock)();
21 |
22 | /*!
23 | The consumer view of a CancellationToken.
24 | Propagates notification that operations should be canceled.
25 | A OSSCancellationToken has methods to inspect whether the token has been cancelled.
26 | */
27 | @interface OSSCancellationToken : NSObject
28 |
29 | /*!
30 | Whether cancellation has been requested for this token source.
31 | */
32 | @property (nonatomic, assign, readonly, getter=isCancellationRequested) BOOL cancellationRequested;
33 |
34 | /*!
35 | Register a block to be notified when the token is cancelled.
36 | If the token is already cancelled the delegate will be notified immediately.
37 | */
38 | - (OSSCancellationTokenRegistration *)registerCancellationObserverWithBlock:(OSSCancellationBlock)block;
39 |
40 | @end
41 |
42 | NS_ASSUME_NONNULL_END
43 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSUtil.h:
--------------------------------------------------------------------------------
1 | //
2 | // OSSUtil.h
3 | // oss_ios_sdk
4 | //
5 | // Created by zhouzhuo on 8/16/15.
6 | // Copyright (c) 2015 aliyun.com. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class OSSFederationToken;
12 |
13 | @interface OSSUtil : NSObject
14 |
15 | + (NSString *)calBase64Sha1WithData:(NSString *)data withSecret:(NSString *)key;
16 | + (NSString *)calBase64WithData:(uint8_t *)data;
17 | + (NSString *)encodeURL:(NSString *)url;
18 | + (NSData *)constructHttpBodyFromPartInfos:(NSArray *)partInfos;
19 | + (NSData *)constructHttpBodyForCreateBucketWithLocation:(NSString *)location;
20 | + (BOOL)validateBucketName:(NSString *)bucketName;
21 | + (BOOL)validateObjectKey:(NSString *)objectKey;
22 | + (BOOL)isOssOriginBucketHost:(NSString *)host;
23 | + (NSString *)getIpByHost:(NSString *)host;
24 | + (BOOL)isNetworkDelegateState;
25 | + (NSString *)dataMD5String:(NSData *)data;
26 | + (NSString *)fileMD5String:(NSString *)path;
27 | + (NSString*)base64ForData:(uint8_t *)input length:(int32_t)length;
28 | + (NSString *)base64Md5ForData:(NSData *)data;
29 | + (NSString *)base64Md5ForFilePath:(NSString *)filePath;
30 | + (NSString *)base64Md5ForFileURL:(NSURL *)fileURL;
31 | + (NSString *)sign:(NSString *)content withToken:(OSSFederationToken *)token;
32 | + (NSString *)getRelativePath:(NSString *)fullPath;
33 | + (NSString *)detemineMimeTypeForFilePath:(NSString *)filePath uploadName:(NSString *)uploadName;
34 | @end
35 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSExecutor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 |
11 | #import
12 |
13 | NS_ASSUME_NONNULL_BEGIN
14 |
15 | /*!
16 | An object that can run a given block.
17 | */
18 | @interface OSSExecutor : NSObject
19 |
20 | /*!
21 | Returns a default executor, which runs continuations immediately until the call stack gets too
22 | deep, then dispatches to a new GCD queue.
23 | */
24 | + (instancetype)defaultExecutor;
25 |
26 | /*!
27 | Returns an executor that runs continuations on the thread where the previous task was completed.
28 | */
29 | + (instancetype)immediateExecutor;
30 |
31 | /*!
32 | Returns an executor that runs continuations on the main thread.
33 | */
34 | + (instancetype)mainThreadExecutor;
35 |
36 | /*!
37 | Returns a new executor that uses the given block to execute continuations.
38 | @param block The block to use.
39 | */
40 | + (instancetype)executorWithBlock:(void(^)(void(^block)()))block;
41 |
42 | /*!
43 | Returns a new executor that runs continuations on the given queue.
44 | @param queue The instance of `dispatch_queue_t` to dispatch all continuations onto.
45 | */
46 | + (instancetype)executorWithDispatchQueue:(dispatch_queue_t)queue;
47 |
48 | /*!
49 | Returns a new executor that runs continuations on the given queue.
50 | @param queue The instance of `NSOperationQueue` to run all continuations on.
51 | */
52 | + (instancetype)executorWithOperationQueue:(NSOperationQueue *)queue;
53 |
54 | /*!
55 | Runs the given block using this executor's particular strategy.
56 | @param block The block to execute.
57 | */
58 | - (void)execute:(void(^)())block;
59 |
60 | @end
61 |
62 | NS_ASSUME_NONNULL_END
63 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSCancellationTokenSource.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 |
11 | #import
12 |
13 | NS_ASSUME_NONNULL_BEGIN
14 |
15 | @class OSSCancellationToken;
16 |
17 | /*!
18 | OSSCancellationTokenSource represents the producer side of a CancellationToken.
19 | Signals to a CancellationToken that it should be canceled.
20 | It is a cancellation token that also has methods
21 | for changing the state of a token by cancelling it.
22 | */
23 | @interface OSSCancellationTokenSource : NSObject
24 |
25 | /*!
26 | Creates a new cancellation token source.
27 | */
28 | + (instancetype)cancellationTokenSource;
29 |
30 | /*!
31 | The cancellation token associated with this CancellationTokenSource.
32 | */
33 | @property (nonatomic, strong, readonly) OSSCancellationToken *token;
34 |
35 | /*!
36 | Whether cancellation has been requested for this token source.
37 | */
38 | @property (nonatomic, assign, readonly, getter=isCancellationRequested) BOOL cancellationRequested;
39 |
40 | /*!
41 | Cancels the token if it has not already been cancelled.
42 | */
43 | - (void)cancel;
44 |
45 | /*!
46 | Schedules a cancel operation on this CancellationTokenSource after the specified number of milliseconds.
47 | @param millis The number of milliseconds to wait before completing the returned task.
48 | If delay is `0` the cancel is executed immediately. If delay is `-1` any scheduled cancellation is stopped.
49 | */
50 | - (void)cancelAfterDelay:(int)millis;
51 |
52 | /*!
53 | Releases all resources associated with this token source,
54 | including disposing of all registrations.
55 | */
56 | - (void)dispose;
57 |
58 | @end
59 |
60 | NS_ASSUME_NONNULL_END
61 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-aliyun-oss
2 |
3 | react-native aliyun oss
4 |
5 | # 安装
6 | ```
7 | npm install git+https://github.com/lesonli/react-native-aliyun-oss.git --save
8 | react-native link
9 | ```
10 |
11 | # 兼容IPv6-Only网络
12 |
13 | OSS移动端SDK为了解决无线网络下域名解析容易遭到劫持的问题,已经引入了HTTPDNS进行域名解析,直接使用IP请求OSS服务端。在IPv6-Only的网络下,可能会遇到兼容性问题。而APP官方近期发布了关于IPv6-only网络环境兼容的APP审核要求,为此,SDK从2.5.0版本开始已经做了兼容性处理。在新版本中,除了-ObjC的设置,还需要引入两个系统库:
14 | ```
15 | libresolv.tbd
16 | SystemConfiguration.framework
17 | ```
18 |
19 | # 使用
20 |
21 | ```
22 |
23 | import AliyunOSS from 'react-native-aliyun-oss'
24 |
25 | AliyunOSS.enableOSSLog();
26 | const config = {
27 | AccessKey: '',
28 | SecretKey: '',
29 | };
30 | const endPoint = '';
31 | AliyunOSS.initWithKey(config, endPoint);
32 |
33 | ...
34 |
35 | // upload
36 | const uploadConfig = {
37 | bucketName: '',
38 | sourceFile: '', // local file path
39 | ossFile: '' // the file path uploaded to oss
40 | };
41 | const uploadProgress = p => console.log(p.currentSize / p.totalSize);
42 | AliyunOSS.addEventListener('uploadProgress', uploadProgress);
43 | await AliyunOSS.uploadObjectAsync(uploadConfig)
44 | .then((resp) => {
45 | console.log(resp);
46 | AliyunOSS.removeEventListener('uploadProgress', uploadProgress);
47 | });
48 |
49 | ...
50 |
51 | // download
52 | const downloadConfig = {
53 | bucketName: '',
54 | ossFile: '' // the file path on the oss
55 | };
56 | const downloadProgress = p => console.log(p.currentSize / p.totalSize);
57 | AliyunOSS.addEventListener('downloadProgress', downloadProgress);
58 | await AliyunOSS.downloadObjectAsync(downloadConfig).then(path => {
59 | console.log(path); // the local file path downloaded from oss
60 | AliyunOSS.removeEventListener('downloadProgress', downloadProgress);
61 | }).catch((error) => {
62 | console.error(error);
63 | });
64 | ```
65 |
66 |
67 | # 注意
68 | AliyunOSS.initWithKey 只用于测试时方便,正式app中建议不要使用
69 |
70 | 正式环境请使用服务器签名,app调用AliyunOSS.initWithSigner
71 |
72 | 详细用法参考index.js中的注释
73 |
74 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSTaskCompletionSource.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 |
11 | #import
12 |
13 | NS_ASSUME_NONNULL_BEGIN
14 |
15 | @class OSSTask;
16 |
17 | /*!
18 | A OSSTaskCompletionSource represents the producer side of tasks.
19 | It is a task that also has methods for changing the state of the
20 | task by settings its completion values.
21 | */
22 | @interface OSSTaskCompletionSource<__covariant ResultType> : NSObject
23 |
24 | /*!
25 | Creates a new unfinished task.
26 | */
27 | + (instancetype)taskCompletionSource;
28 |
29 | /*!
30 | The task associated with this TaskCompletionSource.
31 | */
32 | @property (nonatomic, strong, readonly) OSSTask *task;
33 |
34 | /*!
35 | Completes the task by setting the result.
36 | Attempting to set this for a completed task will raise an exception.
37 | @param result The result of the task.
38 | */
39 | - (void)setResult:(nullable ResultType)result;
40 |
41 | /*!
42 | Completes the task by setting the error.
43 | Attempting to set this for a completed task will raise an exception.
44 | @param error The error for the task.
45 | */
46 | - (void)setError:(NSError *)error;
47 |
48 | /*!
49 | Completes the task by setting an exception.
50 | Attempting to set this for a completed task will raise an exception.
51 | @param exception The exception for the task.
52 | */
53 | - (void)setException:(NSException *)exception;
54 |
55 | /*!
56 | Completes the task by marking it as cancelled.
57 | Attempting to set this for a completed task will raise an exception.
58 | */
59 | - (void)cancel;
60 |
61 | /*!
62 | Sets the result of the task if it wasn't already completed.
63 | @returns whether the new value was set.
64 | */
65 | - (BOOL)trySetResult:(nullable ResultType)result;
66 |
67 | /*!
68 | Sets the error of the task if it wasn't already completed.
69 | @param error The error for the task.
70 | @returns whether the new value was set.
71 | */
72 | - (BOOL)trySetError:(NSError *)error;
73 |
74 | /*!
75 | Sets the exception of the task if it wasn't already completed.
76 | @param exception The exception for the task.
77 | @returns whether the new value was set.
78 | */
79 | - (BOOL)trySetException:(NSException *)exception;
80 |
81 | /*!
82 | Sets the cancellation state of the task if it wasn't already completed.
83 | @returns whether the new value was set.
84 | */
85 | - (BOOL)trySetCancelled;
86 |
87 | @end
88 |
89 | NS_ASSUME_NONNULL_END
90 |
--------------------------------------------------------------------------------
/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSCompat.h:
--------------------------------------------------------------------------------
1 | //
2 | // OSSCompat.h
3 | // oss_ios_sdk_new
4 | //
5 | // Created by zhouzhuo on 9/10/15.
6 | // Copyright (c) 2015 aliyun.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "OSSService.h"
11 |
12 | @class OSSCancellationTokenSource;
13 |
14 | typedef OSSCancellationTokenSource OSSTaskHandler;
15 |
16 | @interface OSSClient (Compat)
17 |
18 | /**
19 | 兼容老版本用法的上传数据接口
20 | 建议更换使用:putObject
21 | */
22 | - (OSSTaskHandler *)uploadData:(NSData *)data
23 | withContentType:(NSString *)contentType
24 | withObjectMeta:(NSDictionary *)meta
25 | toBucketName:(NSString *)bucketName
26 | toObjectKey:(NSString *)objectKey
27 | onCompleted:(void(^)(BOOL, NSError *))onCompleted
28 | onProgress:(void(^)(float progress))onProgress;
29 |
30 | /**
31 | 兼容老版本用法的下载数据接口
32 | 建议更换使用:getObject
33 | */
34 | - (OSSTaskHandler *)downloadToDataFromBucket:(NSString *)bucketName
35 | objectKey:(NSString *)objectKey
36 | onCompleted:(void(^)(NSData *, NSError *))onCompleted
37 | onProgress:(void(^)(float progress))onProgress;
38 |
39 | /**
40 | 兼容老版本用法的上传文件接口
41 | 建议更换使用:putObject
42 | */
43 | - (OSSTaskHandler *)uploadFile:(NSString *)filePath
44 | withContentType:(NSString *)contentType
45 | withObjectMeta:(NSDictionary *)meta
46 | toBucketName:(NSString *)bucketName
47 | toObjectKey:(NSString *)objectKey
48 | onCompleted:(void(^)(BOOL, NSError *))onCompleted
49 | onProgress:(void(^)(float progress))onProgress;
50 |
51 | /**
52 | 兼容老版本用法的下载文件接口
53 | 建议更换使用:getObject
54 | */
55 | - (OSSTaskHandler *)downloadToFileFromBucket:(NSString *)bucketName
56 | objectKey:(NSString *)objectKey
57 | toFile:(NSString *)filePath
58 | onCompleted:(void(^)(BOOL, NSError *))onCompleted
59 | onProgress:(void(^)(float progress))onProgress;
60 |
61 |
62 | /**
63 | 兼容老版本用法的断点上传文件接口
64 | 建议更换使用:resumableUpload
65 | */
66 | - (OSSTaskHandler *)resumableUploadFile:(NSString *)filePath
67 | withContentType:(NSString *)contentType
68 | withObjectMeta:(NSDictionary *)meta
69 | toBucketName:(NSString *)bucketName
70 | toObjectKey:(NSString *)objectKey
71 | onCompleted:(void(^)(BOOL, NSError *))onCompleted
72 | onProgress:(void(^)(float progress))onProgress;
73 |
74 | /**
75 | 兼容老版本用法的删除Object接口
76 | 建议更换使用:deleteObject
77 | */
78 | - (void)deleteObjectInBucket:(NSString *)bucketName
79 | objectKey:(NSString *)objectKey
80 | onCompleted:(void(^)(BOOL, NSError *))onCompleted;
81 | @end
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @flow
3 | */
4 | 'use strict';
5 |
6 | import {
7 | NativeModules,
8 | NativeAppEventEmitter,
9 | NativeEventEmitter,
10 | Platform
11 | } from 'react-native';
12 | const NativeAliyunOSS = NativeModules.AliyunOSS;
13 | const UPLOAD_EVENT = 'uploadProgress';
14 | const DOWNLOAD_EVENT = 'downloadProgress';
15 |
16 | const _subscriptions = new Map();
17 |
18 | const AliyunOSS = {
19 | //开启oss log
20 | enableOSSLog() {
21 | NativeAliyunOSS.enableOSSLog();
22 | },
23 | /*初始化ossclient,
24 | **通过AccessKey和SecretKey
25 | *
26 | */
27 | initWithKey(conf, EndPoint) {
28 | NativeAliyunOSS.initWithKey(conf.AccessKey, conf.SecretKey, EndPoint);
29 | },
30 | /*初始化ossclient,
31 | **通过签名字符串,此处采用的是服务端签名
32 | *
33 | */
34 | initWithSigner(AccessKey, Signature, EndPoint) {
35 | NativeAliyunOSS.initWithSigner(AccessKey, Signature, EndPoint);
36 | },
37 | /*异步上传文件
38 | **bucketName
39 | *sourceFile:源文件路径,例如:/User/xx/xx/test.jpg
40 | *ossFile:目标路径,例如:文件夹/文件名 test/test.jpg
41 | *updateDate:需要和签名中用到的时间一致
42 | */
43 | uploadObjectAsync(conf) {
44 | return NativeAliyunOSS.uploadObjectAsync(
45 | conf.bucketName,
46 | conf.sourceFile,
47 | conf.ossFile,
48 | conf.updateDate);
49 | },
50 |
51 | downloadObjectAsync(conf) {
52 | return NativeAliyunOSS.downloadObjectAsync(
53 | conf.bucketName,
54 | conf.ossFile,
55 | conf.updateDate);
56 | },
57 |
58 | /*监听上传和下载事件,
59 | **返回对象3个属性
60 | *everySentSize:每次上传/下载字节
61 | *currentSize:当前所需上传/下载字节
62 | *totalSize:总字节
63 | */
64 | addEventListener(type, handler) {
65 | var listener;
66 | if (Platform.OS === 'ios') {
67 | const Emitter = new NativeEventEmitter(NativeAliyunOSS);
68 | if (type === UPLOAD_EVENT) {
69 | listener = Emitter.addListener(
70 | 'uploadProgress',
71 | (uploadData) => {
72 | handler(uploadData);
73 | }
74 | );
75 | } else if (type === DOWNLOAD_EVENT) {
76 | listener = Emitter.addListener(
77 | 'downloadProgress',
78 | (downloadData) => {
79 | handler(downloadData);
80 | }
81 | );
82 | } else {
83 | return false;
84 | }
85 | }
86 | else {
87 | if (type === UPLOAD_EVENT) {
88 | listener = NativeAppEventEmitter.addListener(
89 | 'uploadProgress',
90 | (uploadData) => {
91 | handler(uploadData);
92 | }
93 | );
94 | } else if (type === DOWNLOAD_EVENT) {
95 | listener = NativeAppEventEmitter.addListener(
96 | 'downloadProgress',
97 | (downloadData) => {
98 | handler(downloadData);
99 | }
100 | );
101 | } else {
102 | return false;
103 | }
104 | }
105 | _subscriptions.set(handler, listener);
106 | },
107 | removeEventListener(type, handler) {
108 | if (type !== UPLOAD_EVENT && type !== DOWNLOAD_EVENT) {
109 | return false;
110 | }
111 | var listener = _subscriptions.get(handler);
112 | if (!listener) {
113 | return;
114 | }
115 | listener.remove();
116 | _subscriptions.delete(handler);
117 | }
118 | };
119 |
120 | module.exports = AliyunOSS;
121 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSDefine.h:
--------------------------------------------------------------------------------
1 | //
2 | // OSSDefine.h
3 | // AliyunOSSiOS
4 | //
5 | // Created by zhouzhuo on 5/1/16.
6 | // Copyright © 2016 zhouzhuo. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #ifndef OSSDefine_h
12 | #define OSSDefine_h
13 |
14 | #define OSSUAPrefix @"aliyun-sdk-ios"
15 | #define OSSSDKVersion @"2.5.2"
16 |
17 | #define OSSListBucketResultXMLTOKEN @"ListBucketResult"
18 | #define OSSNameXMLTOKEN @"Name"
19 | #define OSSDelimiterXMLTOKEN @"Delimiter"
20 | #define OSSMarkerXMLTOKEN @"Marker"
21 | #define OSSNextMarkerXMLTOKEN @"NextMarker"
22 | #define OSSMaxKeysXMLTOKEN @"MaxKeys"
23 | #define OSSIsTruncatedXMLTOKEN @"IsTruncated"
24 | #define OSSContentsXMLTOKEN @"Contents"
25 | #define OSSKeyXMLTOKEN @"Key"
26 | #define OSSLastModifiedXMLTOKEN @"LastModified"
27 | #define OSSETagXMLTOKEN @"ETag"
28 | #define OSSTypeXMLTOKEN @"Type"
29 | #define OSSSizeXMLTOKEN @"Size"
30 | #define OSSStorageClassXMLTOKEN @"StorageClass"
31 | #define OSSCommonPrefixesXMLTOKEN @"CommonPrefixes"
32 | #define OSSOwnerXMLTOKEN @"Owner"
33 | #define OSSAccessControlListXMLTOKEN @"AccessControlList"
34 | #define OSSGrantXMLTOKEN @"Grant"
35 | #define OSSIDXMLTOKEN @"ID"
36 | #define OSSDisplayNameXMLTOKEN @"DisplayName"
37 | #define OSSBucketsXMLTOKEN @"Buckets"
38 | #define OSSBucketXMLTOKEN @"Bucket"
39 | #define OSSCreationDate @"CreationDate"
40 | #define OSSPrefixXMLTOKEN @"Prefix"
41 | #define OSSUploadIdXMLTOKEN @"UploadId"
42 | #define OSSLocationXMLTOKEN @"Location"
43 | #define OSSNextPartNumberMarkerXMLTOKEN @"NextPartNumberMarker"
44 | #define OSSMaxPartsXMLTOKEN @"MaxParts"
45 | #define OSSPartXMLTOKEN @"Part"
46 | #define OSSPartNumberXMLTOKEN @"PartNumber"
47 |
48 | #define OSSClientErrorDomain @"com.aliyun.oss.clientError"
49 | #define OSSServerErrorDomain @"com.aliyun.oss.serverError"
50 |
51 | #define OSSErrorMessageTOKEN @"ErrorMessage"
52 |
53 | #define OSSHttpHeaderContentDisposition @"Content-Disposition"
54 | #define OSSHttpHeaderXOSSCallback @"x-oss-callback"
55 | #define OSSHttpHeaderXOSSCallbackVar @"x-oss-callback-var"
56 | #define OSSHttpHeaderContentEncoding @"Content-Encoding"
57 | #define OSSHttpHeaderContentType @"Content-Type"
58 | #define OSSHttpHeaderContentMD5 @"Content-MD5"
59 | #define OSSHttpHeaderCacheControl @"Cache-Control"
60 | #define OSSHttpHeaderExpires @"Expires"
61 |
62 | #define OSSDefaultRetryCount 3
63 | #define OSSDefaultMaxConcurrentNum 5
64 | #define OSSDefaultTimeoutForRequestInSecond 15
65 | #define OSSDefaultTimeoutForResourceInSecond 7 * 24 * 60 * 60
66 |
67 | #endif /* OSSDefine_h */
68 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSXMLDictionary.h:
--------------------------------------------------------------------------------
1 | //
2 | // XMLDictionary.h
3 | //
4 | // Version 1.4
5 | //
6 | // Created by Nick Lockwood on 15/11/2010.
7 | // Copyright 2010 Charcoal Design. All rights reserved.
8 | //
9 | // Get the latest version of XMLDictionary from here:
10 | //
11 | // https://github.com/nicklockwood/XMLDictionary
12 | //
13 | // This software is provided 'as-is', without any express or implied
14 | // warranty. In no event will the authors be held liable for any damages
15 | // arising from the use of this software.
16 | //
17 | // Permission is granted to anyone to use this software for any purpose,
18 | // including commercial applications, and to alter it and redistribute it
19 | // freely, subject to the following restrictions:
20 | //
21 | // 1. The origin of this software must not be misrepresented; you must not
22 | // claim that you wrote the original software. If you use this software
23 | // in a product, an acknowledgment in the product documentation would be
24 | // appreciated but is not required.
25 | //
26 | // 2. Altered source versions must be plainly marked as such, and must not be
27 | // misrepresented as being the original software.
28 | //
29 | // 3. This notice may not be removed or altered from any source distribution.
30 | //
31 |
32 | #import
33 | #pragma GCC diagnostic push
34 | #pragma GCC diagnostic ignored "-Wobjc-missing-property-synthesis"
35 |
36 |
37 | typedef NS_ENUM(NSInteger, OSSXMLDictionaryAttributesMode)
38 | {
39 | OSSXMLDictionaryAttributesModePrefixed = 0, //default
40 | OSSXMLDictionaryAttributesModeDictionary,
41 | OSSXMLDictionaryAttributesModeUnprefixed,
42 | OSSXMLDictionaryAttributesModeDiscard
43 | };
44 |
45 |
46 | typedef NS_ENUM(NSInteger, OSSXMLDictionaryNodeNameMode)
47 | {
48 | OSSXMLDictionaryNodeNameModeRootOnly = 0, //default
49 | OSSXMLDictionaryNodeNameModeAlways,
50 | OSSXMLDictionaryNodeNameModeNever
51 | };
52 |
53 |
54 | static NSString *const OSSXMLDictionaryAttributesKey = @"__attributes";
55 | static NSString *const OSSXMLDictionaryCommentsKey = @"__comments";
56 | static NSString *const OSSXMLDictionaryTextKey = @"__text";
57 | static NSString *const OSSXMLDictionaryNodeNameKey = @"__name";
58 | static NSString *const OSSXMLDictionaryAttributePrefix = @"_";
59 |
60 |
61 | @interface OSSXMLDictionaryParser : NSObject
62 |
63 | + (OSSXMLDictionaryParser *)sharedInstance;
64 |
65 | @property (nonatomic, assign) BOOL collapseTextNodes; // defaults to YES
66 | @property (nonatomic, assign) BOOL stripEmptyNodes; // defaults to YES
67 | @property (nonatomic, assign) BOOL trimWhiteSpace; // defaults to YES
68 | @property (nonatomic, assign) BOOL alwaysUseArrays; // defaults to NO
69 | @property (nonatomic, assign) BOOL preserveComments; // defaults to NO
70 | @property (nonatomic, assign) BOOL wrapRootNode; // defaults to NO
71 |
72 | @property (nonatomic, assign) OSSXMLDictionaryAttributesMode attributesMode;
73 | @property (nonatomic, assign) OSSXMLDictionaryNodeNameMode nodeNameMode;
74 |
75 | - (NSDictionary *)dictionaryWithParser:(NSXMLParser *)parser;
76 | - (NSDictionary *)dictionaryWithData:(NSData *)data;
77 | - (NSDictionary *)dictionaryWithString:(NSString *)string;
78 | - (NSDictionary *)dictionaryWithFile:(NSString *)path;
79 |
80 | @end
81 |
82 |
83 | @interface NSDictionary (OSSXMLDictionary)
84 |
85 | + (NSDictionary *)dictionaryWithXMLParser:(NSXMLParser *)parser;
86 | + (NSDictionary *)dictionaryWithXMLData:(NSData *)data;
87 | + (NSDictionary *)dictionaryWithXMLString:(NSString *)string;
88 | + (NSDictionary *)dictionaryWithXMLFile:(NSString *)path;
89 |
90 | - (NSDictionary *)attributes;
91 | - (NSDictionary *)childNodes;
92 | - (NSArray *)comments;
93 | - (NSString *)nodeName;
94 | - (NSString *)innerText;
95 | - (NSString *)innerXML;
96 | - (NSString *)XMLString;
97 |
98 | - (NSArray *)arrayValueForKeyPath:(NSString *)keyPath;
99 | - (NSString *)stringValueForKeyPath:(NSString *)keyPath;
100 | - (NSDictionary *)dictionaryValueForKeyPath:(NSString *)keyPath;
101 |
102 | @end
103 |
104 |
105 | @interface NSString (OSSXMLDictionary)
106 |
107 | - (NSString *)XMLEncodedString;
108 |
109 | @end
110 |
111 |
112 | #pragma GCC diagnostic pop
113 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "_args": [
3 | [
4 | {
5 | "raw": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
6 | "scope": null,
7 | "escapedName": null,
8 | "name": null,
9 | "rawSpec": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
10 | "spec": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
11 | "type": "hosted",
12 | "hosted": {
13 | "type": "github",
14 | "ssh": "git@github.com:lesonli/react-native-aliyun-oss.git",
15 | "sshUrl": "git+ssh://git@github.com/lesonli/react-native-aliyun-oss.git",
16 | "httpsUrl": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
17 | "gitUrl": "git://github.com/lesonli/react-native-aliyun-oss.git",
18 | "shortcut": "github:lesonli/react-native-aliyun-oss",
19 | "directUrl": "https://raw.githubusercontent.com/lesonli/react-native-aliyun-oss/master/package.json"
20 | }
21 | },
22 | "/Users/iou90/Works/Lab/react-native-lab/lab"
23 | ]
24 | ],
25 | "_from": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
26 | "_id": "react-native-aliyun-oss@1.0.0",
27 | "_inCache": true,
28 | "_location": "/react-native-aliyun-oss",
29 | "_phantomChildren": {},
30 | "_requested": {
31 | "raw": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
32 | "scope": null,
33 | "escapedName": null,
34 | "name": null,
35 | "rawSpec": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
36 | "spec": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
37 | "type": "hosted",
38 | "hosted": {
39 | "type": "github",
40 | "ssh": "git@github.com:lesonli/react-native-aliyun-oss.git",
41 | "sshUrl": "git+ssh://git@github.com/lesonli/react-native-aliyun-oss.git",
42 | "httpsUrl": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
43 | "gitUrl": "git://github.com/lesonli/react-native-aliyun-oss.git",
44 | "shortcut": "github:lesonli/react-native-aliyun-oss",
45 | "directUrl": "https://raw.githubusercontent.com/lesonli/react-native-aliyun-oss/master/package.json"
46 | }
47 | },
48 | "_requiredBy": [
49 | "#USER",
50 | "/"
51 | ],
52 | "_resolved": "git+https://github.com/lesonli/react-native-aliyun-oss.git#d0ca918dd141270518f41418231f5569d81c0410",
53 | "_shasum": "4e5481a9a52586d91dd438d70ff56cf0ff86348d",
54 | "_shrinkwrap": null,
55 | "_spec": "git+https://github.com/lesonli/react-native-aliyun-oss.git",
56 | "_where": "/Users/iou90/Works/Lab/react-native-lab/lab",
57 | "author": {
58 | "name": "lesonli"
59 | },
60 | "bugs": {
61 | "url": "https://github.com/lotosbin/react-native-aliyun-oss/issues"
62 | },
63 | "dependencies": {},
64 | "description": "upload file to aliyun oss",
65 | "devDependencies": {},
66 | "gitHead": "8995696bfa55c285fee262b86693333f1200f6f9",
67 | "homepage": "https://github.com/lotosbin/react-native-aliyun-oss#readme",
68 | "keywords": [
69 | "aliyun",
70 | "oss"
71 | ],
72 | "license": "MIT",
73 | "main": "index.js",
74 | "name": "react-native-aliyun-oss",
75 | "optionalDependencies": {},
76 | "readme": "# react-native-aliyun-oss\n\nreact-native aliyun oss\n\n# 安装\n```\nnpm install git+https://github.com/lesonli/react-native-aliyun-oss.git --save\nreact-native link\n```\n# 引入Framework\n\n需要引入OSS iOS SDK framework。\n在Xcode中,直接把framework拖入您对应的Target下即可,在弹出框勾选Copy items if needed。\n\n注意,引入Framework后,需要在工程Build Settings的Other Linker Flags中加入-ObjC。如果工程此前已经设置过-force_load选项,那么,需要加入-force_load /AliyunOSSiOS。\n\n# 兼容IPv6-Only网络\n\nOSS移动端SDK为了解决无线网络下域名解析容易遭到劫持的问题,已经引入了HTTPDNS进行域名解析,直接使用IP请求OSS服务端。在IPv6-Only的网络下,可能会遇到兼容性问题。而APP官方近期发布了关于IPv6-only网络环境兼容的APP审核要求,为此,SDK从2.5.0版本开始已经做了兼容性处理。在新版本中,除了-ObjC的设置,还需要引入两个系统库:\n```\nlibresolv.tbd\nSystemConfiguration.framework\n```\n\n# 使用\n\n```\n\nimport AliyunOSS from 'react-native-aliyun-oss'\n\nAliyunOSS.enableOSSLog();\n\n let key_conf = {\n AccessKey:'xxxxxxx',\n SecretKey:'xxxxxxxxxxxxxx',\n };\n let EndPoint = 'https://oss-cn-qingdao.aliyuncs.com'; \n AliyunOSS.initWithKey(key_conf,EndPoint);\n \n ...\n \n let date = new Date();\n date = date.toGMTString();\n \n let upload_conf = {\nbucketName:'xxxx',\nsourceFile:'',\nossFile:'test/file1m',\nupdateDate:date};\n let uploadProgress = data => console.log(data);\n AliyunOSS.addEventListener('uploadProgress',uploadProgress);\n AliyunOSS.uploadObjectAsync(upload_conf)\n .then((resp) => {\n console.log(resp);\n AliyunOSS.removeEventListener('uploadProgress',uploadProgress);\n });\n```\n\n# 注意\nAliyunOSS.initWithKey 只用于测试时方便,正式app中建议不要使用\n\n正式环境请使用服务器签名,app调用AliyunOSS.initWithSigner\n\n详细用法参考index.ios.js中的注释\n\n当前版本只封装了下载功能,后续更新下载功能\n\n",
77 | "readmeFilename": "README.md",
78 | "repository": {
79 | "type": "git",
80 | "url": "git+https://github.com/lotosbin/react-native-aliyun-oss.git"
81 | },
82 | "version": "1.0.1"
83 | }
84 |
--------------------------------------------------------------------------------
/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSNetworking.h:
--------------------------------------------------------------------------------
1 | //
2 | // OSSNetworking.h
3 | // oss_ios_sdk
4 | //
5 | // Created by zhouzhuo on 8/16/15.
6 | // Copyright (c) 2015 aliyun.com. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "OSSModel.h"
11 |
12 | @class OSSSyncMutableDictionary;
13 | @class OSSNetworkingRequestDelegate;
14 | @class OSSExecutor;
15 |
16 | /**
17 | 定义重试类型
18 | */
19 | typedef NS_ENUM(NSInteger, OSSNetworkingRetryType) {
20 | OSSNetworkingRetryTypeUnknown,
21 | OSSNetworkingRetryTypeShouldRetry,
22 | OSSNetworkingRetryTypeShouldNotRetry,
23 | OSSNetworkingRetryTypeShouldRefreshCredentialsAndRetry,
24 | OSSNetworkingRetryTypeShouldCorrectClockSkewAndRetry
25 | };
26 |
27 | /**
28 | 重试处理器
29 | */
30 | @interface OSSURLRequestRetryHandler : NSObject
31 | @property (nonatomic, assign) uint32_t maxRetryCount;
32 |
33 | - (OSSNetworkingRetryType)shouldRetry:(uint32_t)currentRetryCount
34 | requestDelegate:(OSSNetworkingRequestDelegate *)delegate
35 | response:(NSHTTPURLResponse *)response
36 | error:(NSError *)error;
37 |
38 | - (NSTimeInterval)timeIntervalForRetry:(uint32_t)currentRetryCount
39 | retryType:(OSSNetworkingRetryType)retryType;
40 |
41 | + (instancetype)defaultRetryHandler;
42 | @end
43 |
44 | /**
45 | 网络参数设置
46 | */
47 | @interface OSSNetworkingConfiguration : NSObject
48 | @property (nonatomic, assign) uint32_t maxRetryCount;
49 | @property (nonatomic, assign) uint32_t maxConcurrentRequestCount;
50 | @property (nonatomic, assign) BOOL enableBackgroundTransmitService;
51 | @property (nonatomic, strong) NSString * backgroundSessionIdentifier;
52 | @property (nonatomic, assign) NSTimeInterval timeoutIntervalForRequest;
53 | @property (nonatomic, assign) NSTimeInterval timeoutIntervalForResource;
54 | @property (nonatomic, strong) NSString * proxyHost;
55 | @property (nonatomic, strong) NSNumber * proxyPort;
56 | @end
57 |
58 | /**
59 | 对操作发起的每一次请求构造一个信息代理
60 | */
61 | @interface OSSNetworkingRequestDelegate : NSObject
62 |
63 | @property (nonatomic, strong) NSMutableArray * interceptors;
64 | @property (nonatomic, strong) OSSAllRequestNeededMessage * allNeededMessage;
65 | @property (nonatomic, strong) NSMutableURLRequest * internalRequest;
66 | @property (nonatomic, assign) OSSOperationType operType;
67 | @property (nonatomic, assign) BOOL isAccessViaProxy;
68 |
69 | @property (nonatomic, assign) BOOL isRequestCancelled;
70 |
71 | @property (nonatomic, strong) OSSHttpResponseParser * responseParser;
72 |
73 | @property (nonatomic, strong) NSData * uploadingData;
74 | @property (nonatomic, strong) NSURL * uploadingFileURL;
75 |
76 | @property (nonatomic, assign) int64_t payloadTotalBytesWritten;
77 |
78 | @property (nonatomic, assign) BOOL isBackgroundUploadFileTask;
79 | @property (nonatomic, assign) BOOL isHttpdnsEnable;
80 |
81 | @property (nonatomic, strong) OSSURLRequestRetryHandler * retryHandler;
82 | @property (nonatomic, assign) uint32_t currentRetryCount;
83 | @property (nonatomic, strong) NSError * error;
84 | @property (nonatomic, assign) BOOL isHttpRequestNotSuccessResponse;
85 | @property (nonatomic, strong) NSMutableData * httpRequestNotSuccessResponseBody;
86 |
87 | @property (atomic, strong) NSURLSessionDataTask * currentSessionTask;
88 |
89 | @property (nonatomic, copy) OSSNetworkingUploadProgressBlock uploadProgress;
90 | @property (nonatomic, copy) OSSNetworkingDownloadProgressBlock downloadProgress;
91 | @property (nonatomic, copy) OSSNetworkingCompletionHandlerBlock completionHandler;
92 | @property (nonatomic, copy) OSSNetworkingOnRecieveDataBlock onRecieveData;
93 |
94 | - (OSSTask *)buildInternalHttpRequest;
95 | - (void)reset;
96 | - (void)cancel;
97 | @end
98 |
99 | /**
100 | 包含一次网络请求所需的所有信息
101 | */
102 | @interface OSSAllRequestNeededMessage : NSObject
103 | @property (nonatomic, strong) NSString * endpoint;
104 | @property (nonatomic, strong) NSString * httpMethod;
105 | @property (nonatomic, strong) NSString * bucketName;
106 | @property (nonatomic, strong) NSString * objectKey;
107 | @property (nonatomic, strong) NSString * contentType;
108 | @property (nonatomic, strong) NSString * contentMd5;
109 | @property (nonatomic, strong) NSString * range;
110 | @property (nonatomic, strong) NSString * date;
111 | @property (nonatomic, strong) NSMutableDictionary * headerParams;
112 | @property (nonatomic, strong) NSMutableDictionary * querys;
113 |
114 | @property (nonatomic, assign) BOOL isHostInCnameExcludeList;
115 |
116 | - (instancetype)initWithEndpoint:(NSString *)endpoint
117 | httpMethod:(NSString *)httpMethod
118 | bucketName:(NSString *)bucketName
119 | objectKey:(NSString *)objectKey
120 | type:(NSString *)contentType
121 | md5:(NSString *)contentMd5
122 | range:(NSString *)range
123 | date:(NSString *)date
124 | headerParams:(NSMutableDictionary *)headerParams
125 | querys:(NSMutableDictionary *)querys;
126 |
127 | - (OSSTask *)validateRequestParamsInOperationType:(OSSOperationType)operType;
128 | @end
129 |
130 | /**
131 | 每个OSSClient持有一个OSSNetworking用以收发网络请求
132 | */
133 | @interface OSSNetworking : NSObject
134 | @property (nonatomic, strong) NSURLSession * dataSession;
135 | @property (nonatomic, strong) NSURLSession * uploadFileSession;
136 | @property (nonatomic, assign) BOOL isUsingBackgroundSession;
137 | @property (nonatomic, strong) OSSSyncMutableDictionary * sessionDelagateManager;
138 | @property (nonatomic, strong) OSSNetworkingConfiguration * configuration;
139 | @property (nonatomic, strong) OSSExecutor * taskExecutor;
140 |
141 | - (instancetype)initWithConfiguration:(OSSNetworkingConfiguration *)configuration;
142 | - (OSSTask *)sendRequest:(OSSNetworkingRequestDelegate *)request;
143 | @end
144 |
--------------------------------------------------------------------------------
/ios/RCTAliyunOSS/RCTAliyunOSS.m:
--------------------------------------------------------------------------------
1 | //
2 | // RCTAliyunOSS.m
3 | // RCTAliyunOSS
4 | //
5 | // Created by 李京生 on 2016/10/26.
6 | // Copyright © 2016年 lesonli. All rights reserved.
7 | //
8 |
9 | #import "RCTAliyunOSS.h"
10 | #import "RCTLog.h"
11 | #import "OSSService.h"
12 |
13 |
14 | @implementation RCTAliyunOSS{
15 |
16 | OSSClient *client;
17 |
18 | }
19 |
20 | - (NSArray *)supportedEvents {
21 | return @[@"uploadProgress", @"downloadProgress"];
22 | }
23 |
24 | // get local file dir which is readwrite able
25 | - (NSString *)getDocumentDirectory {
26 | NSString * path = NSHomeDirectory();
27 | NSLog(@"NSHomeDirectory:%@",path);
28 | NSString * userName = NSUserName();
29 | NSString * rootPath = NSHomeDirectoryForUser(userName);
30 | NSLog(@"NSHomeDirectoryForUser:%@",rootPath);
31 | NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
32 | NSString * documentsDirectory = [paths objectAtIndex:0];
33 | return documentsDirectory;
34 | }
35 |
36 | RCT_EXPORT_MODULE()
37 |
38 | RCT_EXPORT_METHOD(enableOSSLog) {
39 | // 打开调试log
40 | [OSSLog enableLog];
41 | RCTLogInfo(@"OSSLog: 已开启");
42 | }
43 | // 由阿里云颁发的AccessKeyId/AccessKeySecret初始化客户端。
44 | // 明文设置secret的方式建议只在测试时使用,
45 | // 如果已经在bucket上绑定cname,将该cname直接设置到endPoint即可
46 | RCT_EXPORT_METHOD(initWithKey:(NSString *)AccessKey
47 | SecretKey:(NSString *)SecretKey
48 | Endpoint:(NSString *)Endpoint){
49 |
50 | id credential = [[OSSPlainTextAKSKPairCredentialProvider alloc] initWithPlainTextAccessKey:AccessKey secretKey:SecretKey];
51 |
52 | OSSClientConfiguration * conf = [OSSClientConfiguration new];
53 | conf.maxRetryCount = 3;
54 | conf.timeoutIntervalForRequest = 30;
55 | conf.timeoutIntervalForResource = 24 * 60 * 60;
56 |
57 | client = [[OSSClient alloc] initWithEndpoint:Endpoint credentialProvider:credential clientConfiguration:conf];
58 | }
59 |
60 | //通过签名方式初始化,需要服务端实现签名字符串,签名算法参考阿里云文档
61 | RCT_EXPORT_METHOD(initWithSigner:(NSString *)AccessKey
62 | Signature:(NSString *)Signature
63 | Endpoint:(NSString *)Endpoint){
64 |
65 | // 自实现签名,可以用本地签名也可以远程加签
66 | id credential1 = [[OSSCustomSignerCredentialProvider alloc] initWithImplementedSigner:^NSString *(NSString *contentToSign, NSError *__autoreleasing *error) {
67 | //NSString *signature = [OSSUtil calBase64Sha1WithData:contentToSign withSecret:@""];
68 | if (Signature != nil) {
69 | *error = nil;
70 | } else {
71 | // construct error object
72 | *error = [NSError errorWithDomain:Endpoint code:OSSClientErrorCodeSignFailed userInfo:nil];
73 | return nil;
74 | }
75 | //return [NSString stringWithFormat:@"OSS %@:%@", @"", signature];
76 | return [NSString stringWithFormat:@"OSS %@:%@", AccessKey, Signature];
77 | }];
78 |
79 |
80 | OSSClientConfiguration * conf = [OSSClientConfiguration new];
81 | conf.maxRetryCount = 1;
82 | conf.timeoutIntervalForRequest = 30;
83 | conf.timeoutIntervalForResource = 24 * 60 * 60;
84 |
85 | client = [[OSSClient alloc] initWithEndpoint:Endpoint credentialProvider:credential1 clientConfiguration:conf];
86 | }
87 |
88 | //异步下载
89 | RCT_REMAP_METHOD(downloadObjectAsync, bucketName:(NSString *)bucketName objectKey:(NSString *)objectKey updateDate:(NSString *)updateDate resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
90 | OSSGetObjectRequest *request = [OSSGetObjectRequest new];
91 | // required
92 | request.bucketName = bucketName;
93 | request.objectKey = objectKey;
94 | // optional
95 | request.downloadProgress = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
96 | NSLog(@"%lld, %lld, %lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite);
97 | [self sendEventWithName: @"downloadProgress" body:@{@"everySentSize":[NSString stringWithFormat:@"%lld",bytesWritten],
98 | @"currentSize": [NSString stringWithFormat:@"%lld",totalBytesWritten],
99 | @"totalSize": [NSString stringWithFormat:@"%lld",totalBytesExpectedToWrite]}];
100 | };
101 | NSString *docDir = [self getDocumentDirectory];
102 | NSLog(objectKey);
103 | NSURL *url = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:objectKey]];
104 | request.downloadToFileURL = url;
105 | OSSTask *getTask = [client getObject:request];
106 | [getTask continueWithBlock:^id(OSSTask *task) {
107 | if (!task.error) {
108 | NSLog(@"download object success!");
109 | OSSGetObjectResult *result = task.result;
110 | NSLog(@"download dota length: %lu", [result.downloadedData length]);
111 | resolve(url.absoluteString);
112 | } else {
113 | NSLog(@"download object failed, error: %@" ,task.error);
114 | reject(nil, @"download object failed", task.error);
115 | }
116 | return nil;
117 | }];
118 | }
119 |
120 | //异步上传
121 | RCT_REMAP_METHOD(uploadObjectAsync, bucketName:(NSString *)BucketName
122 | SourceFile:(NSString *)SourceFile
123 | OssFile:(NSString *)OssFile
124 | UpdateDate:(NSString *)UpdateDate
125 | resolver:(RCTPromiseResolveBlock)resolve
126 | rejecter:(RCTPromiseRejectBlock)reject) {
127 |
128 | OSSPutObjectRequest * put = [OSSPutObjectRequest new];
129 |
130 | // required fields
131 | put.bucketName = BucketName;
132 | put.objectKey = OssFile;
133 | //NSString * docDir = [self getDocumentDirectory];
134 | //put.uploadingFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"file1m"]];
135 | put.uploadingFileURL = [NSURL fileURLWithPath:SourceFile];
136 | NSLog(@"uploadingFileURL: %@", put.uploadingFileURL);
137 | // optional fields
138 | put.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
139 | NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
140 | [self sendEventWithName: @"uploadProgress" body:@{@"everySentSize":[NSString stringWithFormat:@"%lld",bytesSent],
141 | @"currentSize": [NSString stringWithFormat:@"%lld",totalByteSent],
142 | @"totalSize": [NSString stringWithFormat:@"%lld",totalBytesExpectedToSend]}];
143 |
144 | };
145 | //put.contentType = @"";
146 | //put.contentMd5 = @"";
147 | //put.contentEncoding = @"";
148 | //put.contentDisposition = @"";
149 | put.objectMeta = [NSMutableDictionary dictionaryWithObjectsAndKeys: UpdateDate, @"Date", nil];
150 |
151 | OSSTask * putTask = [client putObject:put];
152 |
153 | [putTask continueWithBlock:^id(OSSTask *task) {
154 | NSLog(@"objectKey: %@", put.objectKey);
155 | if (!task.error) {
156 | NSLog(@"upload object success!");
157 | resolve(@YES);
158 | } else {
159 | NSLog(@"upload object failed, error: %@" , task.error);
160 | reject(@"-1", @"not respond this method", nil);
161 | }
162 | return nil;
163 | }];
164 | }
165 |
166 |
167 |
168 | @end
169 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSClient.h:
--------------------------------------------------------------------------------
1 | //
2 | // OSSClient.h
3 | // oss_ios_sdk
4 | //
5 | // Created by zhouzhuo on 8/16/15.
6 | // Copyright (c) 2015 aliyun.com. All rights reserved.
7 | //
8 |
9 | #import
10 | @class OSSGetServiceRequest;
11 | @class OSSCreateBucketRequest;
12 | @class OSSDeleteBucketRequest;
13 | @class OSSHeadObjectRequest;
14 | @class OSSGetBucketRequest;
15 | @class OSSGetBucketACLRequest;
16 | @class OSSGetObjectRequest;
17 | @class OSSPutObjectRequest;
18 | @class OSSPutObjectACLRequest;
19 | @class OSSDeleteObjectRequest;
20 | @class OSSCopyObjectRequest;
21 | @class OSSInitMultipartUploadRequest;
22 | @class OSSUploadPartRequest;
23 | @class OSSCompleteMultipartUploadRequest;
24 | @class OSSListPartsRequest;
25 | @class OSSAbortMultipartUploadRequest;
26 | @class OSSAppendObjectRequest;
27 | @class OSSResumableUploadRequest;
28 | @class OSSTask;
29 | @class OSSExecutor;
30 |
31 | @class OSSNetworking;
32 | @class OSSClientConfiguration;
33 | @protocol OSSCredentialProvider;
34 |
35 | /**
36 | OSSClient是OSS服务的iOS客户端,它为调用者提供了一系列的方法,用于和OSS服务进行交互。
37 | 一般来说,全局内只需要保持一个OSSClient,用来调用各种操作。
38 | */
39 | @interface OSSClient : NSObject
40 |
41 | /**
42 | OSS访问域名
43 | */
44 | @property (nonatomic, strong) NSString * endpoint;
45 |
46 | /**
47 | 用以收发网络请求
48 | */
49 | @property (nonatomic, strong) OSSNetworking * networking;
50 |
51 | /**
52 | 提供访问所需凭证
53 | */
54 | @property (nonatomic, strong) id credentialProvider;
55 |
56 | /**
57 | 客户端设置
58 | */
59 | @property (nonatomic, strong) OSSClientConfiguration * clientConfiguration;
60 |
61 | /**
62 | 任务队列
63 | */
64 | @property (nonatomic, strong, readonly) OSSExecutor * ossOperationExecutor;
65 |
66 | /**
67 | 初始化OSSClient,使用默认的本地设置
68 | @endpoint 指明Bucket所在的Region域名
69 | @credentialProvider 需要实现的签名器
70 | */
71 | - (instancetype)initWithEndpoint:(NSString *)endpoint
72 | credentialProvider:(id) credentialProvider;
73 |
74 | /**
75 | 初始化OSSClient,使用自定义设置
76 | @endpoint 指明Bucket所在的Region域名
77 | @credentialProvider 需要实现的签名器
78 | @conf 可以设置一些本地参数如重试次数、超时时间等
79 | */
80 | - (instancetype)initWithEndpoint:(NSString *)endpoint
81 | credentialProvider:(id)credentialProvider
82 | clientConfiguration:(OSSClientConfiguration *)conf;
83 |
84 | #pragma mark restful-api
85 |
86 | /**
87 | 对应RESTFul API:GetService
88 | 获取请求者当前拥有的全部Bucket。
89 | 注意:
90 | 1. 尚不支持STS;
91 | 2. 当所有的bucket都返回时,返回的xml中不包含Prefix、Marker、MaxKeys、IsTruncated、NextMarker节点,如果还有部分结果未返回,则增加上述节点,其中NextMarker用于继续查询时给marker赋值。
92 | */
93 | - (OSSTask *)getService:(OSSGetServiceRequest *)request;
94 |
95 | /**
96 | 对应RESTFul API:PutBucket
97 | 用于创建Bucket(不支持匿名访问)。默认情况下,创建的Bucket位于默认的数据中心:oss-cn-hangzhou。
98 | 用户可以显式指定Bucket位于的数据中心,从而最优化延迟,最小化费用或者满足监管要求等。
99 | 注意:
100 | 1. 尚不支持STS。
101 | */
102 | - (OSSTask *)createBucket:(OSSCreateBucketRequest *)request;
103 |
104 | /**
105 | 对应RESTFul API:DeleteBucket
106 | 用于删除某个Bucket。
107 | */
108 | - (OSSTask *)deleteBucket:(OSSDeleteBucketRequest *)request;
109 |
110 | /**
111 | 对应RESTFul API:GetBucket
112 | 用来list Bucket中所有Object的信息,可以通过prefix,marker,delimiter和max-keys对list做限定,返回部分结果。
113 | */
114 | - (OSSTask *)getBucket:(OSSGetBucketRequest *)request;
115 |
116 | /**
117 | 对应RESTFul API:GetBucketACL
118 | 用来获取某个Bucket的访问权限。
119 | */
120 | - (OSSTask *)getBucketACL:(OSSGetBucketACLRequest *)request;
121 |
122 | /**
123 | 对应RESTFul API:HeadObject
124 | 只返回某个Object的meta信息,不返回文件内容。
125 | */
126 | - (OSSTask *)headObject:(OSSHeadObjectRequest *)request;
127 |
128 | /**
129 | 对应RESTFul API:GetObject
130 | 用于获取某个Object,此操作要求用户对该Object有读权限。
131 | */
132 | - (OSSTask *)getObject:(OSSGetObjectRequest *)request;
133 |
134 | /**
135 | 对应RESTFul API:PutObject
136 | 用于上传文件。
137 | */
138 | - (OSSTask *)putObject:(OSSPutObjectRequest *)request;
139 |
140 | /**
141 | Put Object ACL接口用于修改Object的访问权限。目前Object有三种访问权限:private, public-read, public-read-write。
142 | Put Object ACL操作通过Put请求中的“x-oss-object-acl”头来设置,这个操作只有Bucket Owner有权限执行。如果操作成功,则返回200;否则返回相应的错误码和提示信息。
143 | */
144 | - (OSSTask *)putObjectACL:(OSSPutObjectACLRequest *)request;
145 |
146 | /**
147 | 对应RESTFul API:AppendObject
148 | 以追加写的方式上传文件。通过Append Object操作创建的Object类型为Appendable Object,而通过Put Object上传的Object是Normal Object。
149 | */
150 | - (OSSTask *)appendObject:(OSSAppendObjectRequest *)request;
151 |
152 | /**
153 | 对应RESTFul API:copyObject
154 | 拷贝一个在OSS上已经存在的object成另外一个object,可以发送一个PUT请求给OSS,并在PUT请求头中添加元素“x-oss-copy-source”来指定拷贝源。
155 | OSS会自动判断出这是一个Copy操作,并直接在服务器端执行该操作。如果拷贝成功,则返回新的object信息给用户。
156 | 该操作适用于拷贝小于1GB的文件。
157 | */
158 | - (OSSTask *)copyObject:(OSSCopyObjectRequest *)request;
159 |
160 | /**
161 | 对应RESTFul API:DeleteObject
162 | 用于删除某个Object。
163 | */
164 | - (OSSTask *)deleteObject:(OSSDeleteObjectRequest *)request;
165 |
166 | /**
167 | 对应RESTFul API:InitiateMultipartUpload
168 | 使用Multipart Upload模式传输数据前,必须先调用该接口来通知OSS初始化一个Multipart Upload事件。该接口会返回一个OSS服务器创建的全局唯一的Upload ID,用于标识本次Multipart Upload事件。
169 | 用户可以根据这个ID来发起相关的操作,如中止Multipart Upload、查询Multipart Upload等。
170 | */
171 | - (OSSTask *)multipartUploadInit:(OSSInitMultipartUploadRequest *)request;
172 |
173 | /**
174 | 对应RESTFul API:UploadPart
175 | 初始化一个Multipart Upload之后,可以根据指定的Object名和Upload ID来分块(Part)上传数据。
176 | 每一个上传的Part都有一个标识它的号码(part number,范围是1~10,000)。
177 | 对于同一个Upload ID,该号码不但唯一标识这一块数据,也标识了这块数据在整个文件内的相对位置。
178 | 如果你用同一个part号码,上传了新的数据,那么OSS上已有的这个号码的Part数据将被覆盖。除了最后一块Part以外,其他的part最小为100KB;
179 | 最后一块Part没有大小限制。
180 | */
181 | - (OSSTask *)uploadPart:(OSSUploadPartRequest *)request;
182 |
183 | /**
184 | 对应RESTFul API:CompleteMultipartUpload
185 | 在将所有数据Part都上传完成后,必须调用Complete Multipart Upload API来完成整个文件的Multipart Upload。
186 | 在执行该操作时,用户必须提供所有有效的数据Part的列表(包括part号码和ETAG);OSS收到用户提交的Part列表后,会逐一验证每个数据Part的有效性。
187 | 当所有的数据Part验证通过后,OSS将把这些数据part组合成一个完整的Object。
188 | */
189 | - (OSSTask *)completeMultipartUpload:(OSSCompleteMultipartUploadRequest *)request;
190 |
191 | /**
192 | 对应RESTFul API:ListParts
193 | 可以罗列出指定Upload ID所属的所有已经上传成功Part。
194 | */
195 | - (OSSTask *)listParts:(OSSListPartsRequest *)request;
196 |
197 | /**
198 | 对应RESTFul API:AbortMultipartUpload
199 | 该接口可以根据用户提供的Upload ID中止其对应的Multipart Upload事件。
200 | 当一个Multipart Upload事件被中止后,就不能再使用这个Upload ID做任何操作,已经上传的Part数据也会被删除。
201 | */
202 | - (OSSTask *)abortMultipartUpload:(OSSAbortMultipartUploadRequest *)request;
203 |
204 | #pragma mark extention method
205 |
206 | /**
207 | 对一个Object签名出一个URL,可以把该URL转给第三方实现授权访问。
208 | @bucketName Object所在的Bucket名称
209 | @objectKey Object名称
210 | @interval 签名URL时,可以指定这个URL的有效时长是多久,单位是秒,比如说需要有效时长为1小时的URL,这里传入3600
211 | */
212 | - (OSSTask *)presignConstrainURLWithBucketName:(NSString *)bucketName
213 | withObjectKey:(NSString *)objectKey
214 | withExpirationInterval:(NSTimeInterval)interval;
215 |
216 | /**
217 | 如果Object的权限是公共读或者公共读写,调用这个接口对该Object签名出一个URL,可以把该URL转给第三方实现授权访问。
218 | @bucketName Object所在的Bucket名称
219 | @objectKey Object名称
220 | */
221 | - (OSSTask *)presignPublicURLWithBucketName:(NSString *)bucketName
222 | withObjectKey:(NSString *)objectKey;
223 |
224 | /**
225 | 断点上传接口
226 | 这个接口封装了分块上传的若干接口以实现断点上传,但是需要用户自行保存UploadId。
227 | 对一个新文件,用户需要首先调用multipartUploadInit接口获得一个UploadId,然后调用此接口上传这个文件。
228 | 如果上传失败,首先需要检查一下失败原因:
229 | 如果非不可恢复的失败,那么可以用同一个UploadId和同一文件继续调用这个接口续传
230 | 否则,需要重新获取UploadId,重新上传这个文件。
231 | 详细参考demo。
232 | */
233 | - (OSSTask *)resumableUpload:(OSSResumableUploadRequest *)request;
234 |
235 | /**
236 | 查看某个Object是否存在
237 | @bucketName Object所在的Bucket名称
238 | @objectKey Object名称
239 |
240 | return YES Object存在
241 | return NO && *error = nil Object不存在
242 | return NO && *error != nil 发生错误
243 | */
244 | - (BOOL)doesObjectExistInBucket:(NSString *)bucketName
245 | objectKey:(NSString *)objectKey
246 | error:(const NSError **)error;
247 | @end
248 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSTask.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 |
11 | #import
12 |
13 | #import "OSSCancellationToken.h"
14 |
15 | NS_ASSUME_NONNULL_BEGIN
16 |
17 | /*!
18 | Error domain used if there was multiple errors on .
19 | */
20 | extern NSString *const OSSTaskErrorDomain;
21 |
22 | /*!
23 | An error code used for , if there were multiple errors.
24 | */
25 | extern NSInteger const kOSSMultipleErrorsError;
26 |
27 | /*!
28 | An exception that is thrown if there was multiple exceptions on .
29 | */
30 | extern NSString *const OSSTaskMultipleExceptionsException;
31 |
32 | /*!
33 | An error userInfo key used if there were multiple errors on .
34 | Value type is `NSArray *`.
35 | */
36 | extern NSString *const OSSTaskMultipleErrorsUserInfoKey;
37 |
38 | /*!
39 | An error userInfo key used if there were multiple exceptions on .
40 | Value type is `NSArray *`.
41 | */
42 | extern NSString *const OSSTaskMultipleExceptionsUserInfoKey;
43 |
44 | @class OSSExecutor;
45 | @class OSSTask;
46 |
47 | /*!
48 | The consumer view of a Task. A OSSTask has methods to
49 | inspect the state of the task, and to add continuations to
50 | be run once the task is complete.
51 | */
52 | @interface OSSTask<__covariant ResultType> : NSObject
53 |
54 | /*!
55 | A block that can act as a continuation for a task.
56 | */
57 | typedef __nullable id(^OSSContinuationBlock)(OSSTask *task);
58 |
59 | /*!
60 | Creates a task that is already completed with the given result.
61 | @param result The result for the task.
62 | */
63 | + (instancetype)taskWithResult:(nullable ResultType)result;
64 |
65 | /*!
66 | Creates a task that is already completed with the given error.
67 | @param error The error for the task.
68 | */
69 | + (instancetype)taskWithError:(NSError *)error;
70 |
71 | /*!
72 | Creates a task that is already completed with the given exception.
73 | @param exception The exception for the task.
74 | */
75 | + (instancetype)taskWithException:(NSException *)exception;
76 |
77 | /*!
78 | Creates a task that is already cancelled.
79 | */
80 | + (instancetype)cancelledTask;
81 |
82 | /*!
83 | Returns a task that will be completed (with result == nil) once
84 | all of the input tasks have completed.
85 | @param tasks An `NSArray` of the tasks to use as an input.
86 | */
87 | + (instancetype)taskForCompletionOfAllTasks:(nullable NSArray *)tasks;
88 |
89 | /*!
90 | Returns a task that will be completed once all of the input tasks have completed.
91 | If all tasks complete successfully without being faulted or cancelled the result will be
92 | an `NSArray` of all task results in the order they were provided.
93 | @param tasks An `NSArray` of the tasks to use as an input.
94 | */
95 | + (instancetype)taskForCompletionOfAllTasksWithResults:(nullable NSArray *)tasks;
96 |
97 | /*!
98 | Returns a task that will be completed once there is at least one successful task.
99 | The first task to successuly complete will set the result, all other tasks results are
100 | ignored.
101 | @param tasks An `NSArray` of the tasks to use as an input.
102 | */
103 | + (instancetype)taskForCompletionOfAnyTask:(nullable NSArray *)tasks;
104 |
105 | /*!
106 | Returns a task that will be completed a certain amount of time in the future.
107 | @param millis The approximate number of milliseconds to wait before the
108 | task will be finished (with result == nil).
109 | */
110 | + (instancetype)taskWithDelay:(int)millis;
111 |
112 | /*!
113 | Returns a task that will be completed a certain amount of time in the future.
114 | @param millis The approximate number of milliseconds to wait before the
115 | task will be finished (with result == nil).
116 | @param token The cancellation token (optional).
117 | */
118 | + (instancetype)taskWithDelay:(int)millis cancellationToken:(nullable OSSCancellationToken *)token;
119 |
120 | /*!
121 | Returns a task that will be completed after the given block completes with
122 | the specified executor.
123 | @param executor A OSSExecutor responsible for determining how the
124 | continuation block will be run.
125 | @param block The block to immediately schedule to run with the given executor.
126 | @returns A task that will be completed after block has run.
127 | If block returns a OSSTask, then the task returned from
128 | this method will not be completed until that task is completed.
129 | */
130 | + (instancetype)taskFromExecutor:(OSSExecutor *)executor withBlock:(nullable id (^)())block;
131 |
132 | // Properties that will be set on the task once it is completed.
133 |
134 | /*!
135 | The result of a successful task.
136 | */
137 | @property (nullable, nonatomic, strong, readonly) ResultType result;
138 |
139 | /*!
140 | The error of a failed task.
141 | */
142 | @property (nullable, nonatomic, strong, readonly) NSError *error;
143 |
144 | /*!
145 | The exception of a failed task.
146 | */
147 | @property (nullable, nonatomic, strong, readonly) NSException *exception;
148 |
149 | /*!
150 | Whether this task has been cancelled.
151 | */
152 | @property (nonatomic, assign, readonly, getter=isCancelled) BOOL cancelled;
153 |
154 | /*!
155 | Whether this task has completed due to an error or exception.
156 | */
157 | @property (nonatomic, assign, readonly, getter=isFaulted) BOOL faulted;
158 |
159 | /*!
160 | Whether this task has completed.
161 | */
162 | @property (nonatomic, assign, readonly, getter=isCompleted) BOOL completed;
163 |
164 | /*!
165 | Enqueues the given block to be run once this task is complete.
166 | This method uses a default execution strategy. The block will be
167 | run on the thread where the previous task completes, unless the
168 | the stack depth is too deep, in which case it will be run on a
169 | dispatch queue with default priority.
170 | @param block The block to be run once this task is complete.
171 | @returns A task that will be completed after block has run.
172 | If block returns a OSSTask, then the task returned from
173 | this method will not be completed until that task is completed.
174 | */
175 | - (OSSTask *)continueWithBlock:(OSSContinuationBlock)block;
176 |
177 | /*!
178 | Enqueues the given block to be run once this task is complete.
179 | This method uses a default execution strategy. The block will be
180 | run on the thread where the previous task completes, unless the
181 | the stack depth is too deep, in which case it will be run on a
182 | dispatch queue with default priority.
183 | @param block The block to be run once this task is complete.
184 | @param cancellationToken The cancellation token (optional).
185 | @returns A task that will be completed after block has run.
186 | If block returns a OSSTask, then the task returned from
187 | this method will not be completed until that task is completed.
188 | */
189 | - (OSSTask *)continueWithBlock:(OSSContinuationBlock)block cancellationToken:(nullable OSSCancellationToken *)cancellationToken;
190 |
191 | /*!
192 | Enqueues the given block to be run once this task is complete.
193 | @param executor A OSSExecutor responsible for determining how the
194 | continuation block will be run.
195 | @param block The block to be run once this task is complete.
196 | @returns A task that will be completed after block has run.
197 | If block returns a OSSTask, then the task returned from
198 | this method will not be completed until that task is completed.
199 | */
200 | - (OSSTask *)continueWithExecutor:(OSSExecutor *)executor withBlock:(OSSContinuationBlock)block;
201 | /*!
202 | Enqueues the given block to be run once this task is complete.
203 | @param executor A OSSExecutor responsible for determining how the
204 | continuation block will be run.
205 | @param block The block to be run once this task is complete.
206 | @param cancellationToken The cancellation token (optional).
207 | @returns A task that will be completed after block has run.
208 | If block returns a OSSTask, then the task returned from
209 | his method will not be completed until that task is completed.
210 | */
211 | - (OSSTask *)continueWithExecutor:(OSSExecutor *)executor
212 | block:(OSSContinuationBlock)block
213 | cancellationToken:(nullable OSSCancellationToken *)cancellationToken;
214 |
215 | /*!
216 | Identical to continueWithBlock:, except that the block is only run
217 | if this task did not produce a cancellation, error, or exception.
218 | If it did, then the failure will be propagated to the returned
219 | task.
220 | @param block The block to be run once this task is complete.
221 | @returns A task that will be completed after block has run.
222 | If block returns a OSSTask, then the task returned from
223 | this method will not be completed until that task is completed.
224 | */
225 | - (OSSTask *)continueWithSuccessBlock:(OSSContinuationBlock)block;
226 |
227 | /*!
228 | Identical to continueWithBlock:, except that the block is only run
229 | if this task did not produce a cancellation, error, or exception.
230 | If it did, then the failure will be propagated to the returned
231 | task.
232 | @param block The block to be run once this task is complete.
233 | @param cancellationToken The cancellation token (optional).
234 | @returns A task that will be completed after block has run.
235 | If block returns a OSSTask, then the task returned from
236 | this method will not be completed until that task is completed.
237 | */
238 | - (OSSTask *)continueWithSuccessBlock:(OSSContinuationBlock)block cancellationToken:(nullable OSSCancellationToken *)cancellationToken;
239 |
240 | /*!
241 | Identical to continueWithExecutor:withBlock:, except that the block
242 | is only run if this task did not produce a cancellation, error, or
243 | exception. If it did, then the failure will be propagated to the
244 | returned task.
245 | @param executor A OSSExecutor responsible for determining how the
246 | continuation block will be run.
247 | @param block The block to be run once this task is complete.
248 | @returns A task that will be completed after block has run.
249 | If block returns a OSSTask, then the task returned from
250 | this method will not be completed until that task is completed.
251 | */
252 | - (OSSTask *)continueWithExecutor:(OSSExecutor *)executor withSuccessBlock:(OSSContinuationBlock)block;
253 |
254 | /*!
255 | Identical to continueWithExecutor:withBlock:, except that the block
256 | is only run if this task did not produce a cancellation, error, or
257 | exception. If it did, then the failure will be propagated to the
258 | returned task.
259 | @param executor A OSSExecutor responsible for determining how the
260 | continuation block will be run.
261 | @param block The block to be run once this task is complete.
262 | @param cancellationToken The cancellation token (optional).
263 | @returns A task that will be completed after block has run.
264 | If block returns a OSSTask, then the task returned from
265 | this method will not be completed until that task is completed.
266 | */
267 | - (OSSTask *)continueWithExecutor:(OSSExecutor *)executor
268 | successBlock:(OSSContinuationBlock)block
269 | cancellationToken:(nullable OSSCancellationToken *)cancellationToken;
270 |
271 | /*!
272 | Waits until this operation is completed.
273 | This method is inefficient and consumes a thread resource while
274 | it's running. It should be avoided. This method logs a warning
275 | message if it is used on the main thread.
276 | */
277 | - (void)waitUntilFinished;
278 |
279 | @end
280 |
281 | NS_ASSUME_NONNULL_END
282 |
--------------------------------------------------------------------------------
/android/src/main/java/com/dskj/dscj/aliyunoss/aliyunossModule.java:
--------------------------------------------------------------------------------
1 | package com.dskj.dscj.aliyunoss;
2 |
3 | import com.alibaba.sdk.android.oss.ClientConfiguration;
4 | import com.alibaba.sdk.android.oss.ClientException;
5 | import com.alibaba.sdk.android.oss.OSS;
6 | import com.alibaba.sdk.android.oss.OSSClient;
7 | import com.alibaba.sdk.android.oss.ServiceException;
8 | import com.alibaba.sdk.android.oss.callback.OSSCompletedCallback;
9 | import com.alibaba.sdk.android.oss.callback.OSSProgressCallback;
10 | import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;
11 | import com.alibaba.sdk.android.oss.common.auth.OSSCustomSignerCredentialProvider;
12 | import com.alibaba.sdk.android.oss.common.auth.OSSPlainTextAKSKCredentialProvider;
13 | import com.alibaba.sdk.android.oss.internal.OSSAsyncTask;
14 | import com.alibaba.sdk.android.oss.model.ObjectMetadata;
15 | import com.alibaba.sdk.android.oss.model.GetObjectRequest;
16 | import com.alibaba.sdk.android.oss.model.GetObjectResult;
17 | import com.alibaba.sdk.android.oss.model.PutObjectRequest;
18 | import com.alibaba.sdk.android.oss.model.PutObjectResult;
19 |
20 | import com.facebook.react.bridge.NativeModule;
21 | import com.facebook.react.bridge.ReactApplicationContext;
22 | import com.facebook.react.bridge.ReactContext;
23 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
24 | import com.facebook.react.bridge.ReactMethod;
25 | import com.facebook.react.bridge.Promise;
26 |
27 | import com.facebook.react.bridge.ReadableMap;
28 | import com.facebook.react.bridge.WritableMap;
29 | import com.facebook.react.bridge.Arguments;
30 | import com.facebook.react.modules.core.DeviceEventManagerModule;
31 |
32 | import java.io.File;
33 | import java.io.FileNotFoundException;
34 | import java.io.FileOutputStream;
35 | import java.io.IOException;
36 | import java.io.InputStream;
37 | import java.lang.String;
38 |
39 | import android.os.Environment;
40 | import android.util.Log;
41 |
42 | /**
43 | * Created by lesonli on 2016/10/31.
44 | */
45 |
46 | public class aliyunossModule extends ReactContextBaseJavaModule {
47 |
48 | private OSS oss;
49 |
50 | public aliyunossModule(ReactApplicationContext reactContext) {
51 | super(reactContext);
52 | }
53 |
54 | @Override
55 | public String getName() {
56 | return "AliyunOSS";
57 | }
58 |
59 | @ReactMethod
60 | public void testPrint(String name, ReadableMap info) {
61 | Log.i("DEBUG", name);
62 | Log.i("DEBUG", info.toString());
63 | }
64 |
65 | @ReactMethod
66 | public void enableOSSLog() {
67 | Log.d("AliyunOSS", "OSSLog 已开启!");
68 | }
69 |
70 | @ReactMethod
71 | public void initWithKey(String accessKey, String secretKey, String endPoint) {
72 | OSSCredentialProvider credentialProvider = new OSSPlainTextAKSKCredentialProvider(accessKey, secretKey);
73 |
74 | ClientConfiguration conf = new ClientConfiguration();
75 | conf.setConnectionTimeout(15 * 1000); // 连接超时,默认15秒
76 | conf.setSocketTimeout(15 * 1000); // socket超时,默认15秒
77 | conf.setMaxConcurrentRequest(5); // 最大并发请求书,默认5个
78 | conf.setMaxErrorRetry(2); // 失败后最大重试次数,默认2次
79 |
80 | oss = new OSSClient(getReactApplicationContext().getApplicationContext(), endPoint, credentialProvider, conf);
81 |
82 | Log.d("AliyunOSS", "OSS initWithKey ok!");
83 | }
84 |
85 | @ReactMethod
86 | public void initWithSigner(final String accessKey, final String signature, String endPoint) {
87 |
88 | OSSCredentialProvider credentialProvider = new OSSCustomSignerCredentialProvider() {
89 | @Override
90 | public String signContent(String content) {
91 | return "OSS " + accessKey + ":" + signature;
92 | }
93 | };
94 |
95 | ClientConfiguration conf = new ClientConfiguration();
96 | conf.setConnectionTimeout(15 * 1000); // 连接超时,默认15秒
97 | conf.setSocketTimeout(15 * 1000); // socket超时,默认15秒
98 | conf.setMaxConcurrentRequest(5); // 最大并发请求书,默认5个
99 | conf.setMaxErrorRetry(2); // 失败后最大重试次数,默认2次
100 |
101 | oss = new OSSClient(getReactApplicationContext().getApplicationContext(), endPoint, credentialProvider, conf);
102 |
103 | Log.d("AliyunOSS", "OSS initWithSigner ok!");
104 | }
105 |
106 | @ReactMethod
107 | public void uploadObjectAsync(String bucketName, String sourceFile, String ossFile, String updateDate, final Promise promise) {
108 | // 构造上传请求
109 | PutObjectRequest put = new PutObjectRequest(bucketName, ossFile, sourceFile);
110 | ObjectMetadata metadata = new ObjectMetadata();
111 | metadata.setHeader("Date",updateDate);
112 | put.setMetadata(metadata);
113 |
114 | // 异步上传时可以设置进度回调
115 | put.setProgressCallback(new OSSProgressCallback() {
116 | @Override
117 | public void onProgress(PutObjectRequest request, long currentSize, long totalSize) {
118 | Log.d("PutObject", "currentSize: " + currentSize + " totalSize: " + totalSize);
119 | String str_currentSize = Long.toString(currentSize);
120 | String str_totalSize = Long.toString(totalSize);
121 | WritableMap onProgressValueData = Arguments.createMap();
122 | onProgressValueData.putString("currentSize", str_currentSize);
123 | onProgressValueData.putString("totalSize", str_totalSize);
124 | getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
125 | .emit("uploadProgress", onProgressValueData);
126 | }
127 | });
128 |
129 | OSSAsyncTask task = oss.asyncPutObject(put, new OSSCompletedCallback() {
130 | @Override
131 | public void onSuccess(PutObjectRequest request, PutObjectResult result) {
132 | Log.d("PutObject", "UploadSuccess");
133 | Log.d("ETag", result.getETag());
134 | Log.d("RequestId", result.getRequestId());
135 | promise.resolve("UploadSuccess");
136 | }
137 |
138 | @Override
139 | public void onFailure(PutObjectRequest request, ClientException clientExcepion, ServiceException serviceException) {
140 | // 请求异常
141 | if (clientExcepion != null) {
142 | // 本地异常如网络异常等
143 | clientExcepion.printStackTrace();
144 | }
145 | if (serviceException != null) {
146 | // 服务异常
147 | Log.e("ErrorCode", serviceException.getErrorCode());
148 | Log.e("RequestId", serviceException.getRequestId());
149 | Log.e("HostId", serviceException.getHostId());
150 | Log.e("RawMessage", serviceException.getRawMessage());
151 | }
152 | promise.reject("UploadFaile", "message:123123");
153 | }
154 | });
155 | Log.d("AliyunOSS", "OSS uploadObjectAsync ok!");
156 | }
157 |
158 | @ReactMethod
159 | public void downloadObjectAsync(String bucketName, String ossFile, String updateDate, final Promise promise) {
160 | // 构造下载文件请求
161 | GetObjectRequest get = new GetObjectRequest(bucketName, ossFile);
162 |
163 | OSSAsyncTask task = oss.asyncGetObject(get, new OSSCompletedCallback() {
164 | @Override
165 | public void onSuccess(GetObjectRequest request, GetObjectResult result) {
166 | // 请求成功
167 | Log.d("Content-Length", "" + result.getContentLength());
168 |
169 | InputStream inputStream = result.getObjectContent();
170 | long resultLength = result.getContentLength();
171 |
172 | byte[] buffer = new byte[2048];
173 | int len;
174 |
175 | FileOutputStream outputStream = null;
176 | String localImgURL = Environment.getExternalStorageDirectory().getAbsolutePath() +
177 | "/ImgCache/" +
178 | System.currentTimeMillis() +
179 | ".jpg";
180 | Log.d("localImgURL", localImgURL);
181 | File cacheFile = new File(localImgURL);
182 | if (!cacheFile.exists()) {
183 | cacheFile.getParentFile().mkdirs();
184 | try {
185 | cacheFile.createNewFile();
186 | } catch (IOException e) {
187 | e.printStackTrace();
188 | promise.reject("DownloadFaile", e);
189 | }
190 | }
191 | long readSize = cacheFile.length();
192 | try {
193 | outputStream = new FileOutputStream(cacheFile, true);
194 | } catch (FileNotFoundException e) {
195 | e.printStackTrace();
196 | promise.reject("DownloadFaile", e);
197 | }
198 | if(resultLength == -1){
199 | promise.reject("DownloadFaile", "message:lengtherror");
200 | }
201 |
202 | try {
203 | while ((len = inputStream.read(buffer)) != -1) {
204 | // 处理下载的数据
205 | try{
206 | outputStream.write(buffer,0,len);
207 | readSize += len;
208 |
209 | String str_currentSize = Long.toString(readSize);
210 | String str_totalSize = Long.toString(resultLength);
211 | WritableMap onProgressValueData = Arguments.createMap();
212 | onProgressValueData.putString("currentSize", str_currentSize);
213 | onProgressValueData.putString("totalSize", str_totalSize);
214 | getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
215 | .emit("downloadProgress", onProgressValueData);
216 |
217 | }catch (IOException e) {
218 | e.printStackTrace();
219 | promise.reject("DownloadFaile", e);
220 | }
221 | }
222 | outputStream.flush();
223 | } catch (IOException e) {
224 | e.printStackTrace();
225 | promise.reject("DownloadFaile", e);
226 | } finally {
227 | if (outputStream != null) {
228 | try {
229 | outputStream.close();
230 | } catch (IOException e) {
231 | promise.reject("DownloadFaile", e);
232 | }
233 | }
234 | if (inputStream != null) {
235 | try {
236 | inputStream.close();
237 | } catch (IOException e) {
238 | promise.reject("DownloadFaile", e);
239 | }
240 | }
241 | promise.resolve(localImgURL);
242 | }
243 | }
244 |
245 | @Override
246 | public void onFailure(GetObjectRequest request, ClientException clientExcepion, ServiceException serviceException) {
247 | // 请求异常
248 | if (clientExcepion != null) {
249 | // 本地异常如网络异常等
250 | clientExcepion.printStackTrace();
251 | }
252 | if (serviceException != null) {
253 | // 服务异常
254 | Log.e("ErrorCode", serviceException.getErrorCode());
255 | Log.e("RequestId", serviceException.getRequestId());
256 | Log.e("HostId", serviceException.getHostId());
257 | Log.e("RawMessage", serviceException.getRawMessage());
258 | }
259 | promise.reject("DownloadFaile", "message:networkerror");
260 | }
261 | });
262 |
263 | // task.cancel(); // 可以取消任务
264 |
265 | // task.waitUntilFinished(); // 如果需要等待任务完成
266 | }
267 | }
268 |
--------------------------------------------------------------------------------
/ios/RCTAliyunOSS.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 00CAEE531DC05BFC003B3B1F /* RCTAliyunOSS.m in Sources */ = {isa = PBXBuildFile; fileRef = 00CAEE521DC05BFC003B3B1F /* RCTAliyunOSS.m */; };
11 | 371D4A561DDDC34B0063F802 /* AliyunOSSiOS in Frameworks */ = {isa = PBXBuildFile; fileRef = 371D4A451DDDC34B0063F802 /* AliyunOSSiOS */; };
12 | /* End PBXBuildFile section */
13 |
14 | /* Begin PBXCopyFilesBuildPhase section */
15 | 00CAEE4C1DC05BFC003B3B1F /* Copy Files */ = {
16 | isa = PBXCopyFilesBuildPhase;
17 | buildActionMask = 2147483647;
18 | dstPath = "include/$(PRODUCT_NAME)";
19 | dstSubfolderSpec = 16;
20 | files = (
21 | );
22 | name = "Copy Files";
23 | runOnlyForDeploymentPostprocessing = 0;
24 | };
25 | /* End PBXCopyFilesBuildPhase section */
26 |
27 | /* Begin PBXFileReference section */
28 | 00CAEE4E1DC05BFC003B3B1F /* libRCTAliyunOSS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTAliyunOSS.a; sourceTree = BUILT_PRODUCTS_DIR; };
29 | 00CAEE511DC05BFC003B3B1F /* RCTAliyunOSS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTAliyunOSS.h; sourceTree = ""; };
30 | 00CAEE521DC05BFC003B3B1F /* RCTAliyunOSS.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTAliyunOSS.m; sourceTree = ""; };
31 | 371D4A451DDDC34B0063F802 /* AliyunOSSiOS */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = AliyunOSSiOS; path = AliyunOSSSDK/AliyunOSSiOS; sourceTree = ""; };
32 | 371D4A461DDDC34B0063F802 /* OSSBolts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSBolts.h; path = AliyunOSSSDK/OSSBolts.h; sourceTree = ""; };
33 | 371D4A471DDDC34B0063F802 /* OSSCancellationToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSCancellationToken.h; path = AliyunOSSSDK/OSSCancellationToken.h; sourceTree = ""; };
34 | 371D4A481DDDC34B0063F802 /* OSSCancellationTokenRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSCancellationTokenRegistration.h; path = AliyunOSSSDK/OSSCancellationTokenRegistration.h; sourceTree = ""; };
35 | 371D4A491DDDC34B0063F802 /* OSSCancellationTokenSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSCancellationTokenSource.h; path = AliyunOSSSDK/OSSCancellationTokenSource.h; sourceTree = ""; };
36 | 371D4A4A1DDDC34B0063F802 /* OSSClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSClient.h; path = AliyunOSSSDK/OSSClient.h; sourceTree = ""; };
37 | 371D4A4B1DDDC34B0063F802 /* OSSCompat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSCompat.h; path = AliyunOSSSDK/OSSCompat.h; sourceTree = ""; };
38 | 371D4A4C1DDDC34B0063F802 /* OSSDefine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSDefine.h; path = AliyunOSSSDK/OSSDefine.h; sourceTree = ""; };
39 | 371D4A4D1DDDC34B0063F802 /* OSSExecutor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSExecutor.h; path = AliyunOSSSDK/OSSExecutor.h; sourceTree = ""; };
40 | 371D4A4E1DDDC34B0063F802 /* OSSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSLog.h; path = AliyunOSSSDK/OSSLog.h; sourceTree = ""; };
41 | 371D4A4F1DDDC34B0063F802 /* OSSModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSModel.h; path = AliyunOSSSDK/OSSModel.h; sourceTree = ""; };
42 | 371D4A501DDDC34B0063F802 /* OSSNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSNetworking.h; path = AliyunOSSSDK/OSSNetworking.h; sourceTree = ""; };
43 | 371D4A511DDDC34B0063F802 /* OSSService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSService.h; path = AliyunOSSSDK/OSSService.h; sourceTree = ""; };
44 | 371D4A521DDDC34B0063F802 /* OSSTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSTask.h; path = AliyunOSSSDK/OSSTask.h; sourceTree = ""; };
45 | 371D4A531DDDC34B0063F802 /* OSSTaskCompletionSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSTaskCompletionSource.h; path = AliyunOSSSDK/OSSTaskCompletionSource.h; sourceTree = ""; };
46 | 371D4A541DDDC34B0063F802 /* OSSUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSUtil.h; path = AliyunOSSSDK/OSSUtil.h; sourceTree = ""; };
47 | 371D4A551DDDC34B0063F802 /* OSSXMLDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OSSXMLDictionary.h; path = AliyunOSSSDK/OSSXMLDictionary.h; sourceTree = ""; };
48 | /* End PBXFileReference section */
49 |
50 | /* Begin PBXFrameworksBuildPhase section */
51 | 00CAEE4B1DC05BFC003B3B1F /* Frameworks */ = {
52 | isa = PBXFrameworksBuildPhase;
53 | buildActionMask = 2147483647;
54 | files = (
55 | 371D4A561DDDC34B0063F802 /* AliyunOSSiOS in Frameworks */,
56 | );
57 | runOnlyForDeploymentPostprocessing = 0;
58 | };
59 | /* End PBXFrameworksBuildPhase section */
60 |
61 | /* Begin PBXGroup section */
62 | 00CAEE451DC05BFC003B3B1F = {
63 | isa = PBXGroup;
64 | children = (
65 | 371D4A3D1DDDC1E50063F802 /* AliyunOSSSDK */,
66 | 00CAEE501DC05BFC003B3B1F /* RCTAliyunOSS */,
67 | 00CAEE4F1DC05BFC003B3B1F /* Products */,
68 | );
69 | sourceTree = "";
70 | };
71 | 00CAEE4F1DC05BFC003B3B1F /* Products */ = {
72 | isa = PBXGroup;
73 | children = (
74 | 00CAEE4E1DC05BFC003B3B1F /* libRCTAliyunOSS.a */,
75 | );
76 | name = Products;
77 | sourceTree = "";
78 | };
79 | 00CAEE501DC05BFC003B3B1F /* RCTAliyunOSS */ = {
80 | isa = PBXGroup;
81 | children = (
82 | 00CAEE511DC05BFC003B3B1F /* RCTAliyunOSS.h */,
83 | 00CAEE521DC05BFC003B3B1F /* RCTAliyunOSS.m */,
84 | );
85 | path = RCTAliyunOSS;
86 | sourceTree = "";
87 | };
88 | 371D4A3D1DDDC1E50063F802 /* AliyunOSSSDK */ = {
89 | isa = PBXGroup;
90 | children = (
91 | 371D4A451DDDC34B0063F802 /* AliyunOSSiOS */,
92 | 371D4A461DDDC34B0063F802 /* OSSBolts.h */,
93 | 371D4A471DDDC34B0063F802 /* OSSCancellationToken.h */,
94 | 371D4A481DDDC34B0063F802 /* OSSCancellationTokenRegistration.h */,
95 | 371D4A491DDDC34B0063F802 /* OSSCancellationTokenSource.h */,
96 | 371D4A4A1DDDC34B0063F802 /* OSSClient.h */,
97 | 371D4A4B1DDDC34B0063F802 /* OSSCompat.h */,
98 | 371D4A4C1DDDC34B0063F802 /* OSSDefine.h */,
99 | 371D4A4D1DDDC34B0063F802 /* OSSExecutor.h */,
100 | 371D4A4E1DDDC34B0063F802 /* OSSLog.h */,
101 | 371D4A4F1DDDC34B0063F802 /* OSSModel.h */,
102 | 371D4A501DDDC34B0063F802 /* OSSNetworking.h */,
103 | 371D4A511DDDC34B0063F802 /* OSSService.h */,
104 | 371D4A521DDDC34B0063F802 /* OSSTask.h */,
105 | 371D4A531DDDC34B0063F802 /* OSSTaskCompletionSource.h */,
106 | 371D4A541DDDC34B0063F802 /* OSSUtil.h */,
107 | 371D4A551DDDC34B0063F802 /* OSSXMLDictionary.h */,
108 | );
109 | name = AliyunOSSSDK;
110 | sourceTree = "";
111 | };
112 | /* End PBXGroup section */
113 |
114 | /* Begin PBXNativeTarget section */
115 | 00CAEE4D1DC05BFC003B3B1F /* RCTAliyunOSS */ = {
116 | isa = PBXNativeTarget;
117 | buildConfigurationList = 00CAEE571DC05BFC003B3B1F /* Build configuration list for PBXNativeTarget "RCTAliyunOSS" */;
118 | buildPhases = (
119 | 00CAEE4A1DC05BFC003B3B1F /* Sources */,
120 | 00CAEE4B1DC05BFC003B3B1F /* Frameworks */,
121 | 00CAEE4C1DC05BFC003B3B1F /* Copy Files */,
122 | );
123 | buildRules = (
124 | );
125 | dependencies = (
126 | );
127 | name = RCTAliyunOSS;
128 | productName = RCTAliyunOSS;
129 | productReference = 00CAEE4E1DC05BFC003B3B1F /* libRCTAliyunOSS.a */;
130 | productType = "com.apple.product-type.library.static";
131 | };
132 | /* End PBXNativeTarget section */
133 |
134 | /* Begin PBXProject section */
135 | 00CAEE461DC05BFC003B3B1F /* Project object */ = {
136 | isa = PBXProject;
137 | attributes = {
138 | LastUpgradeCheck = 0800;
139 | ORGANIZATIONNAME = lesonli;
140 | TargetAttributes = {
141 | 00CAEE4D1DC05BFC003B3B1F = {
142 | CreatedOnToolsVersion = 8.0;
143 | ProvisioningStyle = Automatic;
144 | };
145 | };
146 | };
147 | buildConfigurationList = 00CAEE491DC05BFC003B3B1F /* Build configuration list for PBXProject "RCTAliyunOSS" */;
148 | compatibilityVersion = "Xcode 3.2";
149 | developmentRegion = English;
150 | hasScannedForEncodings = 0;
151 | knownRegions = (
152 | en,
153 | );
154 | mainGroup = 00CAEE451DC05BFC003B3B1F;
155 | productRefGroup = 00CAEE4F1DC05BFC003B3B1F /* Products */;
156 | projectDirPath = "";
157 | projectRoot = "";
158 | targets = (
159 | 00CAEE4D1DC05BFC003B3B1F /* RCTAliyunOSS */,
160 | );
161 | };
162 | /* End PBXProject section */
163 |
164 | /* Begin PBXSourcesBuildPhase section */
165 | 00CAEE4A1DC05BFC003B3B1F /* Sources */ = {
166 | isa = PBXSourcesBuildPhase;
167 | buildActionMask = 2147483647;
168 | files = (
169 | 00CAEE531DC05BFC003B3B1F /* RCTAliyunOSS.m in Sources */,
170 | );
171 | runOnlyForDeploymentPostprocessing = 0;
172 | };
173 | /* End PBXSourcesBuildPhase section */
174 |
175 | /* Begin XCBuildConfiguration section */
176 | 00CAEE551DC05BFC003B3B1F /* Debug */ = {
177 | isa = XCBuildConfiguration;
178 | buildSettings = {
179 | ALWAYS_SEARCH_USER_PATHS = NO;
180 | CLANG_ANALYZER_NONNULL = YES;
181 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
182 | CLANG_CXX_LIBRARY = "libc++";
183 | CLANG_ENABLE_MODULES = YES;
184 | CLANG_ENABLE_OBJC_ARC = YES;
185 | CLANG_WARN_BOOL_CONVERSION = YES;
186 | CLANG_WARN_CONSTANT_CONVERSION = YES;
187 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
188 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
189 | CLANG_WARN_EMPTY_BODY = YES;
190 | CLANG_WARN_ENUM_CONVERSION = YES;
191 | CLANG_WARN_INFINITE_RECURSION = YES;
192 | CLANG_WARN_INT_CONVERSION = YES;
193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
194 | CLANG_WARN_SUSPICIOUS_MOVES = YES;
195 | CLANG_WARN_UNREACHABLE_CODE = YES;
196 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
197 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
198 | COPY_PHASE_STRIP = NO;
199 | DEBUG_INFORMATION_FORMAT = dwarf;
200 | ENABLE_BITCODE = NO;
201 | ENABLE_STRICT_OBJC_MSGSEND = YES;
202 | ENABLE_TESTABILITY = YES;
203 | GCC_C_LANGUAGE_STANDARD = gnu99;
204 | GCC_DYNAMIC_NO_PIC = NO;
205 | GCC_NO_COMMON_BLOCKS = YES;
206 | GCC_OPTIMIZATION_LEVEL = 0;
207 | GCC_PREPROCESSOR_DEFINITIONS = (
208 | "DEBUG=1",
209 | "$(inherited)",
210 | );
211 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
212 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
213 | GCC_WARN_UNDECLARED_SELECTOR = YES;
214 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
215 | GCC_WARN_UNUSED_FUNCTION = YES;
216 | GCC_WARN_UNUSED_VARIABLE = YES;
217 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
218 | MTL_ENABLE_DEBUG_INFO = YES;
219 | ONLY_ACTIVE_ARCH = YES;
220 | SDKROOT = iphoneos;
221 | };
222 | name = Debug;
223 | };
224 | 00CAEE561DC05BFC003B3B1F /* Release */ = {
225 | isa = XCBuildConfiguration;
226 | buildSettings = {
227 | ALWAYS_SEARCH_USER_PATHS = NO;
228 | CLANG_ANALYZER_NONNULL = YES;
229 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
230 | CLANG_CXX_LIBRARY = "libc++";
231 | CLANG_ENABLE_MODULES = YES;
232 | CLANG_ENABLE_OBJC_ARC = YES;
233 | CLANG_WARN_BOOL_CONVERSION = YES;
234 | CLANG_WARN_CONSTANT_CONVERSION = YES;
235 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
236 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
237 | CLANG_WARN_EMPTY_BODY = YES;
238 | CLANG_WARN_ENUM_CONVERSION = YES;
239 | CLANG_WARN_INFINITE_RECURSION = YES;
240 | CLANG_WARN_INT_CONVERSION = YES;
241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
242 | CLANG_WARN_SUSPICIOUS_MOVES = YES;
243 | CLANG_WARN_UNREACHABLE_CODE = YES;
244 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
245 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
246 | COPY_PHASE_STRIP = NO;
247 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
248 | ENABLE_BITCODE = NO;
249 | ENABLE_NS_ASSERTIONS = NO;
250 | ENABLE_STRICT_OBJC_MSGSEND = YES;
251 | GCC_C_LANGUAGE_STANDARD = gnu99;
252 | GCC_NO_COMMON_BLOCKS = YES;
253 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
254 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
255 | GCC_WARN_UNDECLARED_SELECTOR = YES;
256 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
257 | GCC_WARN_UNUSED_FUNCTION = YES;
258 | GCC_WARN_UNUSED_VARIABLE = YES;
259 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
260 | MTL_ENABLE_DEBUG_INFO = NO;
261 | SDKROOT = iphoneos;
262 | VALIDATE_PRODUCT = YES;
263 | };
264 | name = Release;
265 | };
266 | 00CAEE581DC05BFC003B3B1F /* Debug */ = {
267 | isa = XCBuildConfiguration;
268 | buildSettings = {
269 | FRAMEWORK_SEARCH_PATHS = "";
270 | HEADER_SEARCH_PATHS = "$(SRCROOT)/../../react-native/React/**";
271 | LIBRARY_SEARCH_PATHS = (
272 | "$(inherited)",
273 | "$(PROJECT_DIR)/AliyunOSSSDK",
274 | );
275 | OTHER_LDFLAGS = "-ObjC";
276 | PRODUCT_NAME = "$(TARGET_NAME)";
277 | SKIP_INSTALL = YES;
278 | };
279 | name = Debug;
280 | };
281 | 00CAEE591DC05BFC003B3B1F /* Release */ = {
282 | isa = XCBuildConfiguration;
283 | buildSettings = {
284 | FRAMEWORK_SEARCH_PATHS = "";
285 | HEADER_SEARCH_PATHS = "$(SRCROOT)/../../react-native/React/**";
286 | LIBRARY_SEARCH_PATHS = (
287 | "$(PROJECT_DIR)/AliyunOSSSDK",
288 | "$(inherited)",
289 | );
290 | OTHER_LDFLAGS = "-ObjC";
291 | PRODUCT_NAME = "$(TARGET_NAME)";
292 | SKIP_INSTALL = YES;
293 | };
294 | name = Release;
295 | };
296 | /* End XCBuildConfiguration section */
297 |
298 | /* Begin XCConfigurationList section */
299 | 00CAEE491DC05BFC003B3B1F /* Build configuration list for PBXProject "RCTAliyunOSS" */ = {
300 | isa = XCConfigurationList;
301 | buildConfigurations = (
302 | 00CAEE551DC05BFC003B3B1F /* Debug */,
303 | 00CAEE561DC05BFC003B3B1F /* Release */,
304 | );
305 | defaultConfigurationIsVisible = 0;
306 | defaultConfigurationName = Release;
307 | };
308 | 00CAEE571DC05BFC003B3B1F /* Build configuration list for PBXNativeTarget "RCTAliyunOSS" */ = {
309 | isa = XCConfigurationList;
310 | buildConfigurations = (
311 | 00CAEE581DC05BFC003B3B1F /* Debug */,
312 | 00CAEE591DC05BFC003B3B1F /* Release */,
313 | );
314 | defaultConfigurationIsVisible = 0;
315 | defaultConfigurationName = Release;
316 | };
317 | /* End XCConfigurationList section */
318 | };
319 | rootObject = 00CAEE461DC05BFC003B3B1F /* Project object */;
320 | }
321 |
--------------------------------------------------------------------------------
/ios/AliyunOSSSDK/OSSModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // OSSModel.h
3 | // oss_ios_sdk
4 | //
5 | // Created by zhouzhuo on 8/16/15.
6 | // Copyright (c) 2015 aliyun.com. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class OSSAllRequestNeededMessage;
12 | @class OSSFederationToken;
13 | @class OSSTask;
14 |
15 | typedef NS_ENUM(NSInteger, OSSOperationType) {
16 | OSSOperationTypeGetService,
17 | OSSOperationTypeCreateBucket,
18 | OSSOperationTypeDeleteBucket,
19 | OSSOperationTypeGetBucket,
20 | OSSOperationTypeGetBucketACL,
21 | OSSOperationTypeHeadObject,
22 | OSSOperationTypeGetObject,
23 | OSSOperationTypePutObject,
24 | OSSOperationTypePutObjectACL,
25 | OSSOperationTypeAppendObject,
26 | OSSOperationTypeDeleteObject,
27 | OSSOperationTypeCopyObject,
28 | OSSOperationTypeInitMultipartUpload,
29 | OSSOperationTypeUploadPart,
30 | OSSOperationTypeCompleteMultipartUpload,
31 | OSSOperationTypeAbortMultipartUpload,
32 | OSSOperationTypeListMultipart
33 | };
34 |
35 | typedef NS_ENUM(NSInteger, OSSClientErrorCODE) {
36 | OSSClientErrorCodeNetworkingFailWithResponseCode0,
37 | OSSClientErrorCodeSignFailed,
38 | OSSClientErrorCodeFileCantWrite,
39 | OSSClientErrorCodeInvalidArgument,
40 | OSSClientErrorCodeNilUploadid,
41 | OSSClientErrorCodeTaskCancelled,
42 | OSSClientErrorCodeNetworkError,
43 | OSSClientErrorCodeCannotResumeUpload,
44 | OSSClientErrorCodeExcpetionCatched,
45 | OSSClientErrorCodeNotKnown
46 | };
47 |
48 | typedef void (^OSSNetworkingUploadProgressBlock) (int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend);
49 | typedef void (^OSSNetworkingDownloadProgressBlock) (int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite);
50 | typedef void (^OSSNetworkingCompletionHandlerBlock) (id responseObject, NSError *error);
51 | typedef void (^OSSNetworkingOnRecieveDataBlock) (NSData * data);
52 |
53 | typedef NSString * (^OSSCustomSignContentBlock) (NSString * contentToSign, NSError **error);
54 | typedef OSSFederationToken * (^OSSGetFederationTokenBlock) ();
55 |
56 | /**
57 | 扩展NSString
58 | */
59 | @interface NSString (OSS)
60 | - (NSString *)oss_stringByAppendingPathComponentForURL:(NSString *)aString;
61 | - (NSString *)oss_trim;
62 | @end
63 |
64 | /**
65 | 扩展NSDictionary
66 | */
67 | @interface NSDictionary (OSS)
68 | - (NSString *)base64JsonString;
69 | @end
70 |
71 | /**
72 | 扩展NSDate
73 | */
74 | @interface NSDate (OSS)
75 | + (void)oss_setClockSkew:(NSTimeInterval)clockSkew;
76 | + (NSDate *)oss_dateFromString:(NSString *)string;
77 | + (NSDate *)oss_clockSkewFixedDate;
78 | - (NSString *)oss_asStringValue;
79 | @end
80 |
81 | /**
82 | 线程安全的字典
83 | */
84 | @interface OSSSyncMutableDictionary : NSObject
85 | @property (nonatomic, strong) NSMutableDictionary *dictionary;
86 | @property (nonatomic, strong) dispatch_queue_t dispatchQueue;
87 |
88 | - (id)objectForKey:(id)aKey;
89 | - (NSArray *)allKeys;
90 | - (void)setObject:(id)anObject forKey:(id )aKey;
91 | - (void)removeObjectForKey:(id)aKey;
92 | @end
93 |
94 | /**
95 | FederationToken类
96 | */
97 | @interface OSSFederationToken : NSObject
98 | @property (nonatomic, strong) NSString * tAccessKey;
99 | @property (nonatomic, strong) NSString * tSecretKey;
100 | @property (nonatomic, strong) NSString * tToken;
101 |
102 | /**
103 | 指明Token的失效时间,为linux时间对应的毫秒数,即自UTC时间1970年1月1日经过的毫秒数
104 | */
105 | @property (atomic, assign) int64_t expirationTimeInMilliSecond;
106 |
107 | /**
108 | 指明Token的失效时间,格式为GMT字符串,如: "2015-11-03T08:51:05Z"
109 | */
110 | @property (atomic, strong) NSString * expirationTimeInGMTFormat;
111 | @end
112 |
113 | /**
114 | CredentialProvider协议,要求实现加签接口
115 | */
116 | @protocol OSSCredentialProvider
117 | @optional
118 | - (NSString *)sign:(NSString *)content error:(NSError **)error;
119 | @end
120 |
121 | /**
122 | 用明文AK/SK实现的加签器,建议只在测试模式时使用
123 | */
124 | @interface OSSPlainTextAKSKPairCredentialProvider : NSObject
125 | @property (nonatomic, strong) NSString * accessKey;
126 | @property (nonatomic, strong) NSString * secretKey;
127 |
128 | - (instancetype)initWithPlainTextAccessKey:(NSString *)accessKey
129 | secretKey:(NSString *)secretKey;
130 | @end
131 |
132 | /**
133 | 用户自实现加签接口的加签器
134 | */
135 | @interface OSSCustomSignerCredentialProvider : NSObject
136 | @property (nonatomic, copy) NSString * (^signContent)(NSString *, NSError **);
137 |
138 | - (instancetype)initWithImplementedSigner:(OSSCustomSignContentBlock)signContent;
139 | @end
140 |
141 | /**
142 | 用户自实现的通过获取FederationToken来加签的加签器
143 | */
144 | @interface OSSFederationCredentialProvider : NSObject
145 | @property (nonatomic, strong) OSSFederationToken * cachedToken;
146 | @property (nonatomic, copy) OSSFederationToken * (^federationTokenGetter)();
147 |
148 | - (instancetype)initWithFederationTokenGetter:(OSSGetFederationTokenBlock)federationTokenGetter;
149 | - (OSSFederationToken *)getToken:(NSError **)error;
150 | @end
151 |
152 | @interface OSSStsTokenCredentialProvider : NSObject
153 | @property (nonatomic, strong) NSString * accessKeyId;
154 | @property (nonatomic, strong) NSString * secretKeyId;
155 | @property (nonatomic, strong) NSString * securityToken;
156 |
157 | - (OSSFederationToken *)getToken;
158 | - (instancetype)initWithAccessKeyId:(NSString *)accessKeyId
159 | secretKeyId:(NSString *)secretKeyId
160 | securityToken:(NSString *)securityToken;
161 | @end
162 |
163 | /**
164 | OSSClient可以设置的参数
165 | */
166 | @interface OSSClientConfiguration : NSObject
167 |
168 | /**
169 | 最大重试次数
170 | */
171 | @property (nonatomic, assign) uint32_t maxRetryCount;
172 |
173 | /**
174 | 最大并发请求数
175 | */
176 | @property (nonatomic, assign) uint32_t maxConcurrentRequestCount;
177 |
178 | /**
179 | 是否开启后台传输服务
180 | 注意:只在上传文件时有效
181 | */
182 | @property (nonatomic, assign) BOOL enableBackgroundTransmitService;
183 |
184 | /**
185 | 是否使用Httpdns解析域名
186 | */
187 | @property (nonatomic, assign) BOOL isHttpdnsEnable;
188 |
189 | /**
190 | 设置后台传输服务使用session的Id
191 | */
192 | @property (nonatomic, strong) NSString * backgroundSesseionIdentifier;
193 |
194 | /**
195 | 请求超时时间
196 | */
197 | @property (nonatomic, assign) NSTimeInterval timeoutIntervalForRequest;
198 |
199 | /**
200 | 单个Object下载的最长持续时间
201 | */
202 | @property (nonatomic, assign) NSTimeInterval timeoutIntervalForResource;
203 |
204 | /**
205 | 设置代理Host、端口
206 | */
207 | @property (nonatomic, strong) NSString * proxyHost;
208 | @property (nonatomic, strong) NSNumber * proxyPort;
209 |
210 | /**
211 | 设置Cname排除列表
212 | */
213 | @property (nonatomic, strong, setter=setCnameExcludeList:) NSArray * cnameExcludeList;
214 |
215 | @end
216 |
217 | @protocol OSSRequestInterceptor
218 | - (OSSTask *)interceptRequestMessage:(OSSAllRequestNeededMessage *)request;
219 | @end
220 |
221 | /**
222 | 构造请求过程中做加签
223 | */
224 | @interface OSSSignerInterceptor : NSObject
225 | @property (nonatomic, strong) id credentialProvider;
226 |
227 | - (instancetype)initWithCredentialProvider:(id)credentialProvider;
228 | @end
229 |
230 | /**
231 | 构造请求过程中修改UA
232 | */
233 | @interface OSSUASettingInterceptor : NSObject
234 | @end
235 |
236 | /**
237 | 构造请求过程中设置发起请求的标准时间
238 | */
239 | @interface OSSTimeSkewedFixingInterceptor : NSObject
240 | @end
241 |
242 | /**
243 | 下载时指定范围
244 | */
245 | @interface OSSRange : NSObject
246 | @property (nonatomic, assign) int64_t startPosition;
247 | @property (nonatomic, assign) int64_t endPosition;
248 |
249 | - (instancetype)initWithStart:(int64_t)start
250 | withEnd:(int64_t)end;
251 |
252 | /**
253 | * 转换为字符串: 'bytes=${start}-${end}'
254 | */
255 | - (NSString *)toHeaderString;
256 | @end
257 |
258 |
259 | #pragma mark RequestAndResultClass
260 |
261 | /**
262 | 请求头的基类
263 | */
264 | @interface OSSRequest : NSObject
265 | /**
266 | 指明该请求是否需要鉴权,单次有效
267 | */
268 | @property (nonatomic, assign) BOOL isAuthenticationRequired;
269 |
270 | /**
271 | 指明该请求是否已经被取消
272 | */
273 | @property (nonatomic, assign) BOOL isCancelled;
274 |
275 | /**
276 | 取消这个请求
277 | */
278 | - (void)cancel;
279 | @end
280 |
281 | /**
282 | 请求结果的基类
283 | */
284 | @interface OSSResult : NSObject
285 |
286 | /**
287 | 请求HTTP响应码
288 | */
289 | @property (nonatomic, assign) NSInteger httpResponseCode;
290 |
291 | /**
292 | 请求HTTP响应头部,以KV形式放在字典中
293 | */
294 | @property (nonatomic, strong) NSDictionary * httpResponseHeaderFields;
295 |
296 | /**
297 | x-oss-request-id是由Aliyun OSS创建,并唯一标识这个response的UUID。如果在使用OSS服务时遇到问题,可以凭借该字段联系OSS工作人员,快速定位问题。
298 | */
299 | @property (nonatomic, strong) NSString * requestId;
300 | @end
301 |
302 | /**
303 | 罗列用户拥有的所有Bucket的请求。
304 | */
305 | @interface OSSGetServiceRequest : OSSRequest
306 |
307 | /**
308 | 限定返回的bucket name必须以prefix作为前缀,可以不设定,不设定时不过滤前缀信息
309 | */
310 | @property (nonatomic, strong) NSString * prefix;
311 |
312 | /**
313 | 设定结果从marker之后按字母排序的第一个开始返回,可以不设定,不设定时从头开始返回
314 | */
315 | @property (nonatomic, strong) NSString * marker;
316 |
317 | /**
318 | 限定此次返回bucket的最大数,如果不设定,默认为100,max-keys取值不能大于1000
319 | */
320 | @property (nonatomic, assign) int32_t maxKeys;
321 |
322 |
323 | /**
324 | 根据参数各字段构造URL中的查询串
325 | */
326 | - (NSMutableDictionary *)getQueryDict;
327 | @end
328 |
329 | /**
330 | 罗列用户拥有的所有Bucket的请求结果
331 | */
332 | @interface OSSGetServiceResult : OSSResult
333 |
334 | /**
335 | Bucket拥有者的用户ID
336 | */
337 | @property (nonatomic, strong) NSString * ownerId;
338 |
339 | /**
340 | Bucket拥有者的名称 (目前和ID一致)。
341 | */
342 | @property (nonatomic, strong) NSString * ownerDispName;
343 |
344 | /**
345 | 本次查询结果的前缀,当bucket未全部返回时才有此节点
346 | */
347 | @property (nonatomic, strong) NSString * prefix;
348 |
349 | /**
350 | 标明这次GetService(ListBucket)的起点,当bucket未全部返回时才有此节点
351 | */
352 | @property (nonatomic, strong) NSString * marker;
353 |
354 | /**
355 | 响应请求内返回结果的最大数目,当bucket未全部返回时才有此节点
356 | */
357 | @property (nonatomic, assign) int32_t maxKeys;
358 |
359 | /**
360 | 指明是否所有的结果都已经返回:“true”表示本次没有返回全部结果;“false”表示本次已经返回了全部结果。当bucket未全部返回时才有此节点。
361 | */
362 | @property (nonatomic, assign) BOOL isTruncated;
363 |
364 | /**
365 | 表示下一次GetService(ListBucket)可以以此为marker,将未返回的结果返回。当bucket未全部返回时才有此节点。
366 | */
367 | @property (nonatomic, strong) NSString * nextMarker;
368 |
369 | /**
370 | 保存bucket信息的容器,结构上是一个数组,数组每个元素是一个字典,字典的key有 ["Name", "CreationDate", "Location" ]
371 | */
372 | @property (nonatomic, strong) NSArray * buckets;
373 | @end
374 |
375 | /**
376 | 创建Bucket的请求
377 | */
378 | @interface OSSCreateBucketRequest : OSSRequest
379 |
380 | /**
381 | 要创建的Bucket的名称
382 | */
383 | @property (nonatomic, strong) NSString * bucketName;
384 |
385 | /**
386 | 指定Bucket所在的数据中心。
387 | 关于数据中心和终端域名的更多内容,参见访问域名和数据中心https://docs.aliyun.com/#/pub/oss/product-documentation/domain-region
388 | */
389 | @property (nonatomic, strong) NSString * location;
390 |
391 | /**
392 | 设置Bucket 访问权限。目前Bucket有三种访问权限:public-read-write,public-read和private。
393 | */
394 | @property (nonatomic, strong) NSString * xOssACL;
395 | @end
396 |
397 | /**
398 | 创建Bucket的请求结果
399 | */
400 | @interface OSSCreateBucketResult : OSSResult
401 |
402 | /**
403 | Bucket所在的数据中心
404 | */
405 | @property (nonatomic, strong) NSString * location;
406 | @end
407 |
408 | /**
409 | 删除Bucket的请求
410 | */
411 | @interface OSSDeleteBucketRequest : OSSRequest
412 |
413 | /**
414 | Bucket的名称
415 | */
416 | @property (nonatomic, strong) NSString * bucketName;
417 | @end
418 |
419 | /**
420 | 删除Bucket的请求结果
421 | */
422 | @interface OSSDeleteBucketResult : OSSResult
423 | @end
424 |
425 | /**
426 | 罗列Bucket中Objects的请求
427 | */
428 | @interface OSSGetBucketRequest : OSSRequest
429 |
430 | /**
431 | Bucket名称
432 | */
433 | @property (nonatomic, strong) NSString * bucketName;
434 |
435 | /**
436 | 是一个用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现delimiter字符之间的object作为一组元素——CommonPrefixes。
437 | */
438 | @property (nonatomic, strong) NSString * delimiter;
439 |
440 | /**
441 | 设定结果从marker之后按字母排序的第一个开始返回。
442 | */
443 | @property (nonatomic, strong) NSString * marker;
444 |
445 | /**
446 | 限定此次返回object的最大数,如果不设定,默认为100,max-keys取值不能大于1000。
447 | */
448 | @property (nonatomic, assign) int32_t maxKeys;
449 |
450 | /**
451 | 限定返回的object key必须以prefix作为前缀。注意使用prefix查询时,返回的key中仍会包含prefix。
452 | */
453 | @property (nonatomic, strong) NSString * prefix;
454 |
455 | /**
456 | 根据请求的各个字段生成URL中的查询串
457 | */
458 | - (NSMutableDictionary *)getQueryDict;
459 | @end
460 |
461 | /**
462 | 罗列Bucket中Objects的请求结果
463 | */
464 | @interface OSSGetBucketResult : OSSResult
465 |
466 | /**
467 | Bucket名称
468 | */
469 | @property (nonatomic, strong) NSString * bucketName;
470 |
471 | /**
472 | 限定返回的object key必须以prefix作为前缀。注意使用prefix查询时,返回的key中仍会包含prefix。
473 | */
474 | @property (nonatomic, strong) NSString * prefix;
475 |
476 | /**
477 | 设定结果从marker之后按字母排序的第一个开始返回。
478 | */
479 | @property (nonatomic, strong) NSString * marker;
480 |
481 | /**
482 | 限定此次返回object的最大数,如果不设定,默认为100,max-keys取值不能大于1000。
483 | */
484 | @property (nonatomic, assign) int32_t maxKeys;
485 |
486 | /**
487 | 是一个用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现delimiter字符之间的object作为一组元素——CommonPrefixes。
488 | */
489 | @property (nonatomic, strong) NSString * delimiter;
490 |
491 | /**
492 | 如果因为max-keys的设定无法一次完成listing,返回结果会附加一个,提示继续listing可以以此为marker。
493 | NextMarker中的值仍在list结果之中。
494 | */
495 | @property (nonatomic, strong) NSString * nextMarker;
496 |
497 | /**
498 | 指明是否所有的结果都已经返回; “true”表示本次没有返回全部结果;“false”表示本次已经返回了全部结果。
499 | */
500 | @property (nonatomic, assign) BOOL isTruncated;
501 |
502 | /**
503 | 装载文件信息的容器,结构为一个数组,数组中元素是一个个字典,代表每个文件,字典的key有 [ "Key", "LastModified", "ETag", "Type", "Size", "StorageClass", "Owner" ]
504 | */
505 | @property (nonatomic, strong) NSArray * contents;
506 |
507 | /**
508 | 装载公共前缀信息的容器,结构为一个数组,数组中元素是NSString,每个代表一个前缀
509 | */
510 | @property (nonatomic, strong) NSArray * commentPrefixes;
511 | @end
512 |
513 | /**
514 | 获取指定Bucket的读写权限
515 | */
516 | @interface OSSGetBucketACLRequest : OSSRequest
517 |
518 | /**
519 | Bucket名称
520 | */
521 | @property (nonatomic, strong) NSString * bucketName;
522 | @end
523 |
524 | /**
525 | 获取指定Bucket的ACL的请求结果
526 | */
527 | @interface OSSGetBucketACLResult : OSSResult
528 |
529 | /**
530 | 获取到的Bucket的ACL,有 private/public-read/public-read-write
531 | */
532 | @property (nonatomic, strong) NSString * aclGranted;
533 | @end
534 |
535 | /**
536 | 获取Object Meta信息的请求
537 | */
538 | @interface OSSHeadObjectRequest : OSSRequest
539 |
540 | /**
541 | Object所在Bucket的名称
542 | */
543 | @property (nonatomic, strong) NSString * bucketName;
544 |
545 | /**
546 | Object名称
547 | */
548 | @property (nonatomic, strong) NSString * objectKey;
549 | @end
550 |
551 | /**
552 | 获取Object Meta信息的结果
553 | */
554 | @interface OSSHeadObjectResult : OSSResult
555 |
556 | /**
557 | Obejct的Meta信息
558 | */
559 | @property (nonatomic, strong) NSDictionary * objectMeta;
560 | @end
561 |
562 | /**
563 | 下载Object的请求头
564 | */
565 | @interface OSSGetObjectRequest : OSSRequest
566 |
567 | /**
568 | Bucket名称
569 | */
570 | @property (nonatomic, strong) NSString * bucketName;
571 |
572 | /**
573 | Object名称
574 | */
575 | @property (nonatomic, strong) NSString * objectKey;
576 |
577 | /**
578 | 指定文件传输的范围。如,设定 bytes=0-9,表示传送第0到第9这10个字符。
579 | */
580 | @property (nonatomic, strong) OSSRange * range;
581 |
582 | /**
583 | 如果希望Object直接下载到文件中,通过这个字段指明文件地址
584 | */
585 | @property (nonatomic, strong) NSURL * downloadToFileURL;
586 |
587 | /**
588 | 图片处理配置
589 | */
590 | @property (nonatomic, strong) NSString * xOssProcess;
591 |
592 | /**
593 | 回调下载进度
594 | */
595 | @property (nonatomic, copy) OSSNetworkingDownloadProgressBlock downloadProgress;
596 |
597 | /**
598 | Object下载过程中,会在接收每一段数据后回调这个Block
599 | */
600 | @property (nonatomic, copy) OSSNetworkingOnRecieveDataBlock onRecieveData;
601 | @end
602 |
603 | /**
604 | 下载Object的请求结果
605 | */
606 | @interface OSSGetObjectResult : OSSResult
607 |
608 | /**
609 | 如果下载时未指明下载到文件,那么Object会被下载到内存中,类型为NSData
610 | */
611 | @property (nonatomic, strong) NSData * downloadedData;
612 |
613 | /**
614 | 下载文件时的HTTP响应头的KV字典
615 | */
616 | @property (nonatomic, strong) NSDictionary * objectMeta;
617 | @end
618 |
619 | /**
620 | 修改Object的访问权限请求头
621 | */
622 | @interface OSSPutObjectACLRequest : OSSRequest
623 |
624 | /**
625 | Bucket名称
626 | */
627 | @property (nonatomic, strong) NSString * bucketName;
628 |
629 | /**
630 | Object名称
631 | */
632 | @property (nonatomic, strong) NSString * objectKey;
633 |
634 | /**
635 | */
636 | @property (nonatomic, strong) NSString * acl;
637 |
638 | @end
639 |
640 | /**
641 | 修改Object的访问权限响应
642 | */
643 | @interface OSSPutObjectACLResult : OSSResult
644 | @end
645 |
646 | /**
647 | 上传Object的请求头
648 | */
649 | @interface OSSPutObjectRequest : OSSRequest
650 |
651 | /**
652 | Bucket名称
653 | */
654 | @property (nonatomic, strong) NSString * bucketName;
655 |
656 | /**
657 | Object名称
658 | */
659 | @property (nonatomic, strong) NSString * objectKey;
660 |
661 | /**
662 | 从内存中的NSData上传时,通过这个字段设置
663 | */
664 | @property (nonatomic, strong) NSData * uploadingData;
665 |
666 | /**
667 | 从文件上传时,通过这个字段设置
668 | */
669 | @property (nonatomic, strong) NSURL * uploadingFileURL;
670 |
671 | /**
672 | server回调参数设置
673 | */
674 | @property (nonatomic, strong) NSDictionary * callbackParam;
675 |
676 | /**
677 | server回调变量设置
678 | */
679 | @property (nonatomic, strong) NSDictionary * callbackVar;
680 |
681 | /**
682 | 设置文件类型
683 | */
684 | @property (nonatomic, strong) NSString * contentType;
685 |
686 | /**
687 | 根据协议RFC 1864对消息内容(不包括头部)计算MD5值获得128比特位数字,对该数字进行base64编码为一个消息的Content-MD5值。
688 | 该请求头可用于消息合法性的检查(消息内容是否与发送时一致)。虽然该请求头是可选项,OSS建议用户使用该请求头进行端到端检查。
689 | */
690 | @property (nonatomic, strong) NSString * contentMd5;
691 |
692 | /**
693 | 指定该Object被下载时的名称;更详细描述请参照RFC2616。
694 | */
695 | @property (nonatomic, strong) NSString * contentDisposition;
696 |
697 | /**
698 | 指定该Object被下载时的内容编码格式;更详细描述请参照RFC2616。
699 | */
700 | @property (nonatomic, strong) NSString * contentEncoding;
701 |
702 | /**
703 | 指定该Object被下载时的网页的缓存行为;更详细描述请参照RFC2616。
704 | */
705 | @property (nonatomic, strong) NSString * cacheControl;
706 |
707 | /**
708 | 过期时间(milliseconds);更详细描述请参照RFC2616。
709 | */
710 | @property (nonatomic, strong) NSString * expires;
711 |
712 | /**
713 | 可以在这个字段中携带以x-oss-meta-为前缀的参数,则视为user meta,比如x-oss-meta-location。一个Object可以有多个类似的参数,但所有的user meta总大小不能超过8k。
714 | 如果上传时还需要指定其他HTTP请求头字段,也可以在这里设置
715 | */
716 | @property (nonatomic, strong) NSDictionary * objectMeta;
717 |
718 | /**
719 | 上传进度回调
720 | */
721 | @property (nonatomic, copy) OSSNetworkingUploadProgressBlock uploadProgress;
722 | @end
723 |
724 | /**
725 | 上传Object的请求结果
726 | */
727 | @interface OSSPutObjectResult : OSSResult
728 |
729 | /**
730 | ETag (entity tag) 在每个Object生成的时候被创建,用于标示一个Object的内容。
731 | 对于Put Object请求创建的Object,ETag值是其内容的MD5值;对于其他方式创建的Object,ETag值是其内容的UUID。
732 | ETag值可以用于检查Object内容是否发生变化。
733 | */
734 | @property (nonatomic, strong) NSString * eTag;
735 |
736 | /**
737 | 如果设置了server回调,回调的响应内容
738 | */
739 | @property (nonatomic, strong) NSString * serverReturnJsonString;
740 | @end
741 |
742 | /**
743 | * append object request
744 | */
745 | @interface OSSAppendObjectRequest : OSSRequest
746 |
747 | /**
748 | Bucket名称
749 | */
750 | @property (nonatomic, strong) NSString * bucketName;
751 |
752 | /**
753 | Object名称
754 | */
755 | @property (nonatomic, strong) NSString * objectKey;
756 |
757 | /**
758 | 指定从何处进行追加。首次追加操作的position必须为0,后续追加操作的position是Object的当前长度。
759 | 例如,第一次Append Object请求指定position值为0,content-length是65536;那么,第二次Append Object需要指定position为65536。
760 | 每次操作成功后,响应头部x-oss-next-append-position也会标明下一次追加的position。
761 | */
762 | @property (nonatomic, assign) int64_t appendPosition;
763 |
764 | /**
765 | 从内存中的NSData上传时,通过这个字段设置
766 | */
767 | @property (nonatomic, strong) NSData * uploadingData;
768 |
769 | /**
770 | 从文件上传时,通过这个字段设置
771 | */
772 | @property (nonatomic, strong) NSURL * uploadingFileURL;
773 |
774 | /**
775 | 设置文件类型
776 | */
777 | @property (nonatomic, strong) NSString * contentType;
778 |
779 | /**
780 | 根据协议RFC 1864对消息内容(不包括头部)计算MD5值获得128比特位数字,对该数字进行base64编码为一个消息的Content-MD5值。
781 | 该请求头可用于消息合法性的检查(消息内容是否与发送时一致)。虽然该请求头是可选项,OSS建议用户使用该请求头进行端到端检查。
782 | */
783 | @property (nonatomic, strong) NSString * contentMd5;
784 |
785 | /**
786 | 指定该Object被下载时的名称;更详细描述请参照RFC2616。
787 | */
788 | @property (nonatomic, strong) NSString * contentDisposition;
789 |
790 | /**
791 | 指定该Object被下载时的内容编码格式;更详细描述请参照RFC2616。
792 | */
793 | @property (nonatomic, strong) NSString * contentEncoding;
794 |
795 | /**
796 | 指定该Object被下载时的网页的缓存行为;更详细描述请参照RFC2616。
797 | */
798 | @property (nonatomic, strong) NSString * cacheControl;
799 |
800 | /**
801 | 过期时间(milliseconds);更详细描述请参照RFC2616。
802 | */
803 | @property (nonatomic, strong) NSString * expires;
804 |
805 | /**
806 | 可以在这个字段中携带以x-oss-meta-为前缀的参数,则视为user meta,比如x-oss-meta-location。一个Object可以有多个类似的参数,但所有的user meta总大小不能超过8k。
807 | 如果上传时还需要指定其他HTTP请求头字段,也可以在这里设置
808 | */
809 | @property (nonatomic, strong) NSDictionary * objectMeta;
810 |
811 | /**
812 | 上传进度回调
813 | */
814 | @property (nonatomic, copy) OSSNetworkingUploadProgressBlock uploadProgress;
815 | @end
816 |
817 | /**
818 | * append object result
819 | */
820 | @interface OSSAppendObjectResult : OSSResult
821 |
822 | /**
823 | ETag (entity tag) 在每个Object生成的时候被创建,用于标示一个Object的内容。
824 | 对于Put Object请求创建的Object,ETag值是其内容的MD5值;对于其他方式创建的Object,ETag值是其内容的UUID。
825 | ETag值可以用于检查Object内容是否发生变化。
826 | */
827 | @property (nonatomic, strong) NSString * eTag;
828 |
829 | /**
830 | 指明下一次请求应当提供的position。实际上就是当前Object长度。
831 | 当Append Object成功返回,或是因position和Object长度不匹配而引起的409错误时,会包含此header。
832 | */
833 | @property (nonatomic, assign, readwrite) int64_t xOssNextAppendPosition;
834 | @end
835 |
836 | /**
837 | 删除指定Object
838 | */
839 | @interface OSSDeleteObjectRequest : OSSRequest
840 |
841 | /**
842 | Bucket名称
843 | */
844 | @property (nonatomic, strong) NSString * bucketName;
845 |
846 | /**
847 | Object名称
848 | */
849 | @property (nonatomic, strong) NSString * objectKey;
850 | @end
851 |
852 | /**
853 | 删除指定Object的响应
854 | */
855 | @interface OSSDeleteObjectResult : OSSResult
856 | @end
857 |
858 | /**
859 | 复制一个Object的请求
860 | */
861 | @interface OSSCopyObjectRequest : OSSRequest
862 |
863 | /**
864 | Bucket名称
865 | */
866 | @property (nonatomic, strong) NSString * bucketName;
867 |
868 | /**
869 | Object名称
870 | */
871 | @property (nonatomic, strong) NSString * objectKey;
872 |
873 | /**
874 | 复制源地址(必须有可读权限)
875 | */
876 | @property (nonatomic, strong) NSString * sourceCopyFrom;
877 |
878 | /**
879 | 设置文件类型
880 | */
881 | @property (nonatomic, strong) NSString * contentType;
882 |
883 | /**
884 | 根据协议RFC 1864对消息内容(不包括头部)计算MD5值获得128比特位数字,对该数字进行base64编码为一个消息的Content-MD5值。
885 | 该请求头可用于消息合法性的检查(消息内容是否与发送时一致)。虽然该请求头是可选项,OSS建议用户使用该请求头进行端到端检查。
886 | */
887 | @property (nonatomic, strong) NSString * contentMd5;
888 |
889 | /**
890 | 可以在这个字段中携带以x-oss-meta-为前缀的参数,则视为user meta,比如x-oss-meta-location。一个Object可以有多个类似的参数,但所有的user meta总大小不能超过8k。
891 | 如果上传时还需要指定其他HTTP请求头字段,也可以在这里设置
892 | */
893 | @property (nonatomic, strong) NSDictionary * objectMeta;
894 | @end
895 |
896 | /**
897 | 复制Object的请求结果
898 | */
899 | @interface OSSCopyObjectResult : OSSResult
900 |
901 | /**
902 | 新Object最后更新时间。
903 | */
904 | @property (nonatomic, strong) NSString * lastModifed;
905 |
906 | /**
907 | 新Object的ETag值。
908 | */
909 | @property (nonatomic, strong) NSString * eTag;
910 | @end
911 |
912 | /**
913 | 初始化分块上传的请求
914 | */
915 | @interface OSSInitMultipartUploadRequest : OSSRequest
916 |
917 | /**
918 | Bucket名称
919 | */
920 | @property (nonatomic, strong) NSString * bucketName;
921 |
922 | /**
923 | Object名称
924 | */
925 | @property (nonatomic, strong) NSString * objectKey;
926 |
927 | /**
928 | 设置文件类型
929 | */
930 | @property (nonatomic, strong) NSString * contentType;
931 |
932 | /**
933 | 指定该Object被下载时的名称;更详细描述请参照RFC2616。
934 | */
935 | @property (nonatomic, strong) NSString * contentDisposition;
936 |
937 | /**
938 | 指定该Object被下载时的内容编码格式;更详细描述请参照RFC2616。
939 | */
940 | @property (nonatomic, strong) NSString * contentEncoding;
941 |
942 | /**
943 | 指定该Object被下载时的网页的缓存行为;更详细描述请参照RFC2616。
944 | */
945 | @property (nonatomic, strong) NSString * cacheControl;
946 |
947 | /**
948 | 过期时间(milliseconds);更详细描述请参照RFC2616。
949 | */
950 | @property (nonatomic, strong) NSString * expires;
951 |
952 | /**
953 | 可以在这个字段中携带以x-oss-meta-为前缀的参数,则视为user meta,比如x-oss-meta-location。一个Object可以有多个类似的参数,但所有的user meta总大小不能超过8k。
954 | 如果上传时还需要指定其他HTTP请求头字段,也可以在这里设置
955 | */
956 | @property (nonatomic, strong) NSDictionary * objectMeta;
957 | @end
958 |
959 | /**
960 | 初始化分块上传的请求结果
961 | */
962 | @interface OSSInitMultipartUploadResult : OSSResult
963 |
964 | /**
965 | 唯一标示此次Multipart Upload事件的ID。
966 | */
967 | @property (nonatomic, strong) NSString * uploadId;
968 | @end
969 |
970 | /**
971 | 上传单个分块的请求
972 | */
973 | @interface OSSUploadPartRequest : OSSRequest
974 |
975 | /**
976 | Bucket名称
977 | */
978 | @property (nonatomic, strong) NSString * bucketName;
979 |
980 | /**
981 | Object名称
982 | */
983 | @property (nonatomic, strong) NSString * objectkey;
984 |
985 | /**
986 | 唯一标示此次Multipart Upload事件的ID。
987 | */
988 | @property (nonatomic, strong) NSString * uploadId;
989 |
990 | /**
991 | 指定本次上传分块的标识号码
992 | */
993 | @property (nonatomic, assign) int partNumber;
994 |
995 | /**
996 | 根据协议RFC 1864对消息内容(不包括头部)计算MD5值获得128比特位数字,对该数字进行base64编码为一个消息的Content-MD5值。
997 | 该请求头可用于消息合法性的检查(消息内容是否与发送时一致)。虽然该请求头是可选项,OSS建议用户使用该请求头进行端到端检查。
998 | */
999 | @property (nonatomic, strong) NSString * contentMd5;
1000 |
1001 | /**
1002 | 从内存中的NSData上传时,通过这个字段设置
1003 | */
1004 | @property (nonatomic, strong) NSData * uploadPartData;
1005 |
1006 | /**
1007 | 从文件上传时,通过这个字段设置
1008 | */
1009 | @property (nonatomic, strong) NSURL * uploadPartFileURL;
1010 |
1011 | /**
1012 | 上传进度回调
1013 | */
1014 | @property (nonatomic, copy) OSSNetworkingUploadProgressBlock uploadPartProgress;
1015 | @end
1016 |
1017 | /**
1018 | 上传单个分块的结果
1019 | */
1020 | @interface OSSUploadPartResult : OSSResult
1021 | @property (nonatomic, strong) NSString * eTag;
1022 | @end
1023 |
1024 | /**
1025 | 分块上传中每个分块的信息,这些信息将会在调用‘完成分块上传’的接口中使用
1026 | */
1027 | @interface OSSPartInfo : NSObject
1028 |
1029 | /**
1030 | 指定本次上传分块的标识号码
1031 | */
1032 | @property (nonatomic, assign) int32_t partNum;
1033 |
1034 | /**
1035 | Part成功上传后,OSS返回的ETag值。
1036 | */
1037 | @property (nonatomic, strong) NSString * eTag;
1038 |
1039 | /**
1040 | 分块数据长度
1041 | */
1042 | @property (nonatomic, assign) int64_t size;
1043 |
1044 | + (instancetype)partInfoWithPartNum:(int32_t)partNum
1045 | eTag:(NSString *)eTag
1046 | size:(int64_t)size;
1047 | @end
1048 |
1049 | /**
1050 | 完成分块上传请求
1051 | */
1052 | @interface OSSCompleteMultipartUploadRequest : OSSRequest
1053 |
1054 | /**
1055 | Bucket名称
1056 | */
1057 | @property (nonatomic, strong) NSString * bucketName;
1058 |
1059 | /**
1060 | Object名称
1061 | */
1062 | @property (nonatomic, strong) NSString * objectKey;
1063 |
1064 | /**
1065 | 唯一标示此次Multipart Upload事件的ID。
1066 | */
1067 | @property (nonatomic, strong) NSString * uploadId;
1068 |
1069 | /**
1070 | 根据协议RFC 1864对消息内容(不包括头部)计算MD5值获得128比特位数字,对该数字进行base64编码为一个消息的Content-MD5值。
1071 | 该请求头可用于消息合法性的检查(消息内容是否与发送时一致)。虽然该请求头是可选项,OSS建议用户使用该请求头进行端到端检查。
1072 | */
1073 | @property (nonatomic, strong) NSString * contentMd5;
1074 |
1075 | /**
1076 | 各个分块的信息
1077 | */
1078 | @property (nonatomic, strong) NSArray * partInfos;
1079 |
1080 | /**
1081 | server回调参数设置
1082 | */
1083 | @property (nonatomic, strong) NSDictionary * callbackParam;
1084 |
1085 | /**
1086 | server回调变量设置
1087 | */
1088 | @property (nonatomic, strong) NSDictionary * callbackVar;
1089 |
1090 | /**
1091 | 完成分块上传附带的请求头
1092 | */
1093 | @property (nonatomic, strong) NSDictionary * completeMetaHeader;
1094 | @end
1095 |
1096 | /**
1097 | 完成分块上传请求的结果
1098 | */
1099 | @interface OSSCompleteMultipartUploadResult : OSSResult
1100 |
1101 | /**
1102 | 新创建Object的URL。
1103 | */
1104 | @property (nonatomic, strong) NSString * location;
1105 |
1106 | /**
1107 | ETag (entity tag) 在每个Object生成的时候被创建,用于标示一个Object的内容。
1108 | Complete Multipart Upload请求创建的Object,ETag值是其内容的UUID。ETag值可以用于检查Object内容是否发生变化。.
1109 | */
1110 | @property (nonatomic, strong) NSString * eTag;
1111 |
1112 | /**
1113 | 如果设置了server回调,回调的响应内容
1114 | */
1115 | @property (nonatomic, strong) NSString * serverReturnJsonString;
1116 | @end
1117 |
1118 | /**
1119 | 罗列某次分块上传事件已经上传的分块请求
1120 | */
1121 | @interface OSSListPartsRequest : OSSRequest
1122 |
1123 | /**
1124 | Bucket名称
1125 | */
1126 | @property (nonatomic, strong) NSString * bucketName;
1127 |
1128 | /**
1129 | Object名称
1130 | */
1131 | @property (nonatomic, strong) NSString * objectKey;
1132 |
1133 | /**
1134 | 唯一标示此次Multipart Upload事件的ID。
1135 | */
1136 | @property (nonatomic, strong) NSString * uploadId;
1137 |
1138 | /**
1139 | 返回请求中最大的Part数目。
1140 | */
1141 | @property (nonatomic, assign) int maxParts;
1142 |
1143 | /**
1144 | 指定List的起始位置,只有Part Number数目大于该参数的Part会被列出。
1145 | */
1146 | @property (nonatomic, assign) int partNumberMarker;
1147 | @end
1148 |
1149 | /**
1150 | 罗列分块请求的结果
1151 | */
1152 | @interface OSSListPartsResult : OSSResult
1153 |
1154 | /**
1155 | 如果本次没有返回全部结果,响应请求中将包含NextPartNumberMarker元素,用于标明接下来请求的PartNumberMarker值。
1156 | */
1157 | @property (nonatomic, assign) int nextPartNumberMarker;
1158 |
1159 | /**
1160 | 返回请求中最大的Part数目。
1161 | */
1162 | @property (nonatomic, assign) int maxParts;
1163 |
1164 | /**
1165 | 标明是否本次返回的List Part结果列表被截断。“true”表示本次没有返回全部结果;“false”表示本次已经返回了全部结果。
1166 | */
1167 | @property (nonatomic, assign) BOOL isTruncated;
1168 |
1169 | /**
1170 | 保存Part信息的容器。
1171 | */
1172 | @property (nonatomic, strong) NSArray * parts;
1173 | @end
1174 |
1175 | /**
1176 | 取消分块上传事件请求
1177 | */
1178 | @interface OSSAbortMultipartUploadRequest : OSSRequest
1179 |
1180 | /**
1181 | Bucket名称
1182 | */
1183 | @property (nonatomic, strong) NSString * bucketName;
1184 |
1185 | /**
1186 | Object名称
1187 | */
1188 | @property (nonatomic, strong) NSString * objectKey;
1189 |
1190 | /**
1191 | 唯一标示此次Multipart Upload事件的ID。
1192 | */
1193 | @property (nonatomic, strong) NSString * uploadId;
1194 | @end
1195 |
1196 | /**
1197 | 取消分块上传事件的结果
1198 | */
1199 | @interface OSSAbortMultipartUploadResult : OSSResult
1200 | @end
1201 |
1202 | /**
1203 | 断点续传请求
1204 | */
1205 | @interface OSSResumableUploadRequest : OSSRequest
1206 |
1207 | /**
1208 | 一个续传事件对应着同一个唯一的UploadId
1209 | */
1210 | @property (nonatomic, strong) NSString * uploadId;
1211 |
1212 | /**
1213 | Bucket名称
1214 | */
1215 | @property (nonatomic, strong) NSString * bucketName;
1216 |
1217 | /**
1218 | Object名称
1219 | */
1220 | @property (nonatomic, strong) NSString * objectKey;
1221 |
1222 | /**
1223 | 从文件上传时,通过这个字段设置
1224 | */
1225 | @property (nonatomic, strong) NSURL * uploadingFileURL;
1226 |
1227 | /**
1228 | 自定义分块大小,最小100KB
1229 | */
1230 | @property (nonatomic, assign) int64_t partSize;
1231 |
1232 | /**
1233 | 上传进度
1234 | */
1235 | @property (nonatomic, copy) OSSNetworkingUploadProgressBlock uploadProgress;
1236 |
1237 | /**
1238 | server回调参数设置
1239 | */
1240 | @property (nonatomic, strong) NSDictionary * callbackParam;
1241 |
1242 | /**
1243 | server回调变量设置
1244 | */
1245 | @property (nonatomic, strong) NSDictionary * callbackVar;
1246 |
1247 | /**
1248 | 完成分块上传附带的请求头
1249 | */
1250 | @property (nonatomic, strong) NSDictionary * completeMetaHeader;
1251 |
1252 | /**
1253 | 当前正在处理的子请求
1254 | */
1255 | @property (atomic, weak) OSSRequest * runningChildrenRequest;
1256 |
1257 | - (void)cancel;
1258 | @end
1259 |
1260 | /**
1261 | 断点续传的结果
1262 | */
1263 | @interface OSSResumableUploadResult : OSSResult
1264 | /**
1265 | 如果设置了server回调,回调的响应内容
1266 | */
1267 | @property (nonatomic, strong) NSString * serverReturnJsonString;
1268 | @end
1269 |
1270 | #pragma mark 其他
1271 |
1272 | /**
1273 | HTTP响应内容解析器
1274 | */
1275 | @interface OSSHttpResponseParser : NSObject
1276 | @property (nonatomic, strong) NSURL * downloadingFileURL;
1277 | @property (nonatomic, copy) OSSNetworkingOnRecieveDataBlock onRecieveBlock;
1278 |
1279 | - (instancetype)initForOperationType:(OSSOperationType)operationType;
1280 | - (void)consumeHttpResponse:(NSHTTPURLResponse *)response;
1281 | - (OSSTask *)consumeHttpResponseBody:(NSData *)data;
1282 | - (id)constructResultObject;
1283 | - (void)reset;
1284 | @end
--------------------------------------------------------------------------------