经过验证,直接使用access_token即可。不用再重新申请了。

遇到的一些小问题:

1.文件夹可以创建多级,比如A/B/C,可以一起创建

2.如果创建失败,有可能是文件夹命名问题。没有找到规律。但是好像叫tlist就不行。

3.上传文件,比较慢。上传一般都启动后台线程操作。

 

创建文件夹

	public void pcs_mkdir(String path) {
		if (null != mbOauth) {
			BaiduPCSClient api = new BaiduPCSClient();
			api.setAccessToken(mbOauth);
			final BaiduPCSActionInfo.PCSFileInfoResponse ret = api.makeDir(path);
			Toast.makeText(conx,
					"Mkdir:  " + ret.status.errorCode
							+ "   " + ret.status.message,
					Toast.LENGTH_SHORT).show();
		}
	}


上传文件

	public void test_upload() {

		if (null != mbOauth) {

			Thread workThread = new Thread(new Runnable() {
				public void run() {

					String tmpFile = "/sdcard/thieflist/temp/temp.png";
					// String tmpFile = "/mnt/sdcard/DCIM/File/1.txt";

					BaiduPCSClient api = new BaiduPCSClient();
					api.setAccessToken(mbOauth);

					final BaiduPCSActionInfo.PCSFileInfoResponse response = api
							.uploadFile(tmpFile, mbRootPath + "temp.png",
									new BaiduPCSStatusListener() {
										@Override
										public void onProgress(long bytes,
												long total) {
											// TODO Auto-generated method stub

											final long bs = bytes;
											final long tl = total;

											mbUiThreadHandler
													.post(new Runnable() {
														public void run() {
															Toast.makeText(
																	conx,
																	"total: "
																			+ tl
																			+ "    sent:"
																			+ bs,
																	Toast.LENGTH_SHORT)
																	.show();
														}
													});
										}

										@Override
										public long progressInterval() {
											return 1000;
										}
									});

					mbUiThreadHandler.post(new Runnable() {
						public void run() {
							Toast.makeText(
									conx,
									response.status.errorCode + "  "
											+ response.status.message + "  "
											+ response.commonFileInfo.blockList,
									Toast.LENGTH_SHORT).show();
						}
					});
				}
			});

			workThread.start();
		}
	}


 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐