├── QiniuUploadDemo ├── .gitignore ├── QiniuUploadDemo.iml ├── build.gradle ├── libs │ ├── happy-dns-0.2.3.2.jar │ ├── okhttp-2.7.0.jar │ ├── okio-1.6.0.jar │ └── qiniu-android-sdk-7.1.2.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── dxy │ │ └── cloud │ │ └── myapplication │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── dxy │ │ │ └── cloud │ │ │ └── myapplication │ │ │ └── MainActivity.java │ ├── libs │ │ ├── happy-dns-0.2.3.2.jar │ │ ├── okhttp-2.7.0.jar │ │ ├── okio-1.6.0.jar │ │ └── qiniu-android-sdk-7.1.2.jar │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── dxy │ └── cloud │ └── myapplication │ └── ExampleUnitTest.java └── README.md /QiniuUploadDemo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /QiniuUploadDemo/QiniuUploadDemo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /QiniuUploadDemo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.dxy.cloud.myapplication" 9 | minSdkVersion 18 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile files('src/main/libs/happy-dns-0.2.3.2.jar') 27 | compile files('src/main/libs/qiniu-android-sdk-7.1.2.jar') 28 | compile files('src/main/libs/okio-1.6.0.jar') 29 | compile files('src/main/libs/okhttp-2.7.0.jar') 30 | } 31 | -------------------------------------------------------------------------------- /QiniuUploadDemo/libs/happy-dns-0.2.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clouddxy/AndroidDemo/cb7cd64dc17ec9fc70fc5c8fbe6e4e6c0aa866ae/QiniuUploadDemo/libs/happy-dns-0.2.3.2.jar -------------------------------------------------------------------------------- /QiniuUploadDemo/libs/okhttp-2.7.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clouddxy/AndroidDemo/cb7cd64dc17ec9fc70fc5c8fbe6e4e6c0aa866ae/QiniuUploadDemo/libs/okhttp-2.7.0.jar -------------------------------------------------------------------------------- /QiniuUploadDemo/libs/okio-1.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clouddxy/AndroidDemo/cb7cd64dc17ec9fc70fc5c8fbe6e4e6c0aa866ae/QiniuUploadDemo/libs/okio-1.6.0.jar -------------------------------------------------------------------------------- /QiniuUploadDemo/libs/qiniu-android-sdk-7.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clouddxy/AndroidDemo/cb7cd64dc17ec9fc70fc5c8fbe6e4e6c0aa866ae/QiniuUploadDemo/libs/qiniu-android-sdk-7.1.2.jar -------------------------------------------------------------------------------- /QiniuUploadDemo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/dxy/android-sdks/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /QiniuUploadDemo/src/androidTest/java/com/dxy/cloud/myapplication/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.dxy.cloud.myapplication; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /QiniuUploadDemo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /QiniuUploadDemo/src/main/java/com/dxy/cloud/myapplication/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.dxy.cloud.myapplication; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.database.Cursor; 6 | import android.graphics.BitmapFactory; 7 | import android.net.Uri; 8 | import android.os.Bundle; 9 | import android.provider.MediaStore; 10 | import android.util.Log; 11 | import android.view.View; 12 | import android.view.View.OnClickListener; 13 | import android.widget.Button; 14 | import android.widget.ImageView; 15 | import android.widget.ProgressBar; 16 | import android.widget.TextView; 17 | 18 | import com.qiniu.android.http.ResponseInfo; 19 | import com.qiniu.android.storage.Configuration; 20 | import com.qiniu.android.storage.KeyGenerator; 21 | import com.qiniu.android.storage.Recorder; 22 | import com.qiniu.android.storage.UpCancellationSignal; 23 | import com.qiniu.android.storage.UpCompletionHandler; 24 | import com.qiniu.android.storage.UpProgressHandler; 25 | import com.qiniu.android.storage.UploadManager; 26 | import com.qiniu.android.storage.UploadOptions; 27 | import com.qiniu.android.storage.persistent.FileRecorder; 28 | import com.qiniu.android.utils.UrlSafeBase64; 29 | 30 | import org.json.JSONObject; 31 | 32 | import java.io.BufferedReader; 33 | import java.io.File; 34 | import java.io.FileNotFoundException; 35 | import java.io.FileReader; 36 | import java.io.IOException; 37 | import java.util.HashMap; 38 | 39 | public class MainActivity extends Activity { 40 | private Button button1; 41 | private Button button2; 42 | private Button button3; 43 | private ImageView imageview; 44 | private Uri imageUri; 45 | private TextView textview; 46 | private ProgressBar progressbar; 47 | public static final int RESULT_LOAD_IMAGE = 1; 48 | private volatile boolean isCancelled = false; 49 | 50 | UploadManager uploadManager; 51 | 52 | 53 | public MainActivity() { 54 | //断点上传 55 | String dirPath = "/storage/emulated/0/Download"; 56 | Recorder recorder = null; 57 | try{ 58 | File f = File.createTempFile("qiniu_xxxx", ".tmp"); 59 | Log.d("qiniu", f.getAbsolutePath().toString()); 60 | dirPath = f.getParent(); 61 | recorder = new FileRecorder(dirPath); 62 | } catch(Exception e) { 63 | e.printStackTrace(); 64 | } 65 | 66 | final String dirPath1 = dirPath; 67 | //默认使用 key 的url_safe_base64编码字符串作为断点记录文件的文件名。 68 | //避免记录文件冲突(特别是key指定为null时),也可自定义文件名(下方为默认实现): 69 | KeyGenerator keyGen = new KeyGenerator(){ 70 | public String gen(String key, File file){ 71 | // 不必使用url_safe_base64转换,uploadManager内部会处理 72 | // 该返回值可替换为基于key、文件内容、上下文的其它信息生成的文件名 73 | String path = key + "_._" + new StringBuffer(file.getAbsolutePath()).reverse(); 74 | Log.d("qiniu", path); 75 | File f = new File(dirPath1, UrlSafeBase64.encodeToString(path)); 76 | BufferedReader reader = null; 77 | try { 78 | reader = new BufferedReader(new FileReader(f)); 79 | String tempString = null; 80 | int line = 1; 81 | try { 82 | while ((tempString = reader.readLine()) != null) { 83 | // System.out.println("line " + line + ": " + tempString); 84 | Log.d("qiniu", "line " + line + ": " + tempString); 85 | line++; 86 | } 87 | 88 | } catch (IOException e) { 89 | // TODO Auto-generated catch block 90 | e.printStackTrace(); 91 | } finally { 92 | try{ 93 | reader.close(); 94 | } catch(Exception e) { 95 | e.printStackTrace(); 96 | } 97 | } 98 | 99 | 100 | 101 | 102 | } catch (FileNotFoundException e) { 103 | // TODO Auto-generated catch block 104 | e.printStackTrace(); 105 | } 106 | return path; 107 | } 108 | }; 109 | 110 | Configuration config = new Configuration.Builder() 111 | // recorder 分片上传时,已上传片记录器 112 | // keyGen 分片上传时,生成标识符,用于片记录器区分是那个文件的上传记录 113 | .recorder(recorder, keyGen) 114 | .build(); 115 | // 实例化一个上传的实例 116 | uploadManager = new UploadManager(config); 117 | } 118 | 119 | @Override 120 | protected void onCreate(Bundle savedInstanceState) { 121 | super.onCreate(savedInstanceState); 122 | setContentView(R.layout.activity_main); 123 | button1 = (Button) findViewById(R.id.bt1); 124 | button2 = (Button) findViewById(R.id.bt2); 125 | button3 = (Button) findViewById(R.id.bt3); 126 | imageview = (ImageView) findViewById(R.id.iv); 127 | textview = (TextView) findViewById(R.id.tv); 128 | progressbar = (ProgressBar) findViewById(R.id.pb); 129 | 130 | // final String token = edittext.getText().toString(); 131 | 132 | button1.setOnClickListener(new OnClickListener() { 133 | @Override 134 | public void onClick(View v) { 135 | Intent i = new Intent( 136 | Intent.ACTION_PICK, 137 | android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 138 | 139 | startActivityForResult(i, RESULT_LOAD_IMAGE); 140 | 141 | } 142 | }); 143 | } 144 | 145 | @Override 146 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 147 | super.onActivityResult(requestCode, resultCode, data); 148 | 149 | if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK 150 | && data != null) { 151 | Uri selectedImage = data.getData(); 152 | String[] filePathColumn = { MediaStore.Images.Media.DATA }; 153 | 154 | Cursor cursor = getContentResolver().query(selectedImage, 155 | filePathColumn, null, null, null); 156 | cursor.moveToFirst(); 157 | 158 | int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 159 | final String picturePath = cursor.getString(columnIndex); 160 | Log.d("PICTUREPATH", picturePath); 161 | cursor.close(); 162 | 163 | imageview.setVisibility(View.VISIBLE); 164 | imageview.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 165 | //永久使用的returnbody测试 166 | // final String token = "um6IEH7mtwnwkGpjImD08JdxlvViuELhI4mFfoeL:gXv-=:eyJzY29wZSI6ImFuZHJvaWRkZW1vIiwiZGVhZGxpbmUiOjIwMDk5MjE5MTIsInJldHVybkJvZHkiOiJ7IFwiaGFzaFwiOiQoZXRhZyksXCJrZXlcIjokKGtleSksXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImZuYW1lXCI6JChmbmFtZSl9In0="; 167 | 168 | //自定义参数returnbody 169 | // final String token = "um6IEH7mtwnwkGpjImD08JdxlvViuELhI4mFfoeL:CJy8mWhEBn5qxhZIyPAg9eHH4iA=:eyJzY29wZSI6ImphdmFkZW1vIiwicmV0dXJuQm9keSI6IntcImtleVwiOiQoa2V5KSxcImhhc2hcIjokKGV0YWcpLFwiZm5hbWVcIjokKGZuYW1lKSxcInBob25lXCI6JCh4OnBob25lKX0iLCJkZWFkbGluZSI6MTQ1OTg0NjQyOH0="; 170 | //自定义参数callbackbody 171 | final String token = "um6IEH7mtwnwkGpjImD08JdxlvViuELhI4mFfoeL:6LM7earlaBgxpLbRApzF_xOMCAk=:eyJjYWxsYmFja1VybCI6Imh0dHA6Ly9hM2VmMDc4YS5uZ3Jvay5pby9TZXJ2bGV0RGVtby9zZXJ2bGV0L0NhbGxiYWNrRGVtbyIsInNjb3BlIjoiamF2YWRlbW8iLCJjYWxsYmFja0JvZHkiOiJuYW1lXHUwMDNkJChmbmFtZSlcdTAwMjZoYXNoXHUwMDNkJChldGFnKVx1MDAyNmtleVx1MDAzZCQoa2V5KVx1MDAyNnBob25lXHUwMDNkJCh4OnBob25lKSIsImRlYWRsaW5lIjoxNDU5ODQ4NDEyfQ=="; 172 | button2.setOnClickListener(new OnClickListener() { 173 | @Override 174 | public void onClick(View v) { 175 | 176 | HashMap map = new HashMap(); 177 | map.put("x:phone", "12345678"); 178 | 179 | Log.d("qiniu", "click upload"); 180 | isCancelled = false; 181 | uploadManager.put(picturePath, null, token, 182 | new UpCompletionHandler() { 183 | public void complete(String key, 184 | ResponseInfo info, JSONObject res) { 185 | Log.i("qiniu", key + ",\r\n " + info 186 | + ",\r\n " + res); 187 | 188 | if(info.isOK()==true){ 189 | textview.setText(res.toString()); 190 | } 191 | } 192 | }, new UploadOptions(map, null, false, 193 | new UpProgressHandler() { 194 | public void progress(String key, double percent){ 195 | Log.i("qiniu", key + ": " + percent); 196 | progressbar.setVisibility(View.VISIBLE); 197 | int progress = (int)(percent*1000); 198 | // Log.d("qiniu", progress+""); 199 | progressbar.setProgress(progress); 200 | if(progress==1000){ 201 | progressbar.setVisibility(View.GONE); 202 | } 203 | } 204 | 205 | }, new UpCancellationSignal(){ 206 | @Override 207 | public boolean isCancelled() { 208 | 209 | return isCancelled; 210 | } 211 | })); 212 | } 213 | }); 214 | 215 | button3.setOnClickListener(new OnClickListener() { 216 | @Override 217 | public void onClick(View v) { 218 | isCancelled = true; 219 | } 220 | }); 221 | 222 | 223 | } 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /QiniuUploadDemo/src/main/libs/happy-dns-0.2.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clouddxy/AndroidDemo/cb7cd64dc17ec9fc70fc5c8fbe6e4e6c0aa866ae/QiniuUploadDemo/src/main/libs/happy-dns-0.2.3.2.jar -------------------------------------------------------------------------------- /QiniuUploadDemo/src/main/libs/okhttp-2.7.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clouddxy/AndroidDemo/cb7cd64dc17ec9fc70fc5c8fbe6e4e6c0aa866ae/QiniuUploadDemo/src/main/libs/okhttp-2.7.0.jar -------------------------------------------------------------------------------- /QiniuUploadDemo/src/main/libs/okio-1.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clouddxy/AndroidDemo/cb7cd64dc17ec9fc70fc5c8fbe6e4e6c0aa866ae/QiniuUploadDemo/src/main/libs/okio-1.6.0.jar -------------------------------------------------------------------------------- /QiniuUploadDemo/src/main/libs/qiniu-android-sdk-7.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clouddxy/AndroidDemo/cb7cd64dc17ec9fc70fc5c8fbe6e4e6c0aa866ae/QiniuUploadDemo/src/main/libs/qiniu-android-sdk-7.1.2.jar -------------------------------------------------------------------------------- /QiniuUploadDemo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 |