Exemplo n.º 1
0
		client.SendRequest(function(res) {
				if (res instanceof Error) {
					console.log(util.inspect(res));
				} else {
					if (res.statusCode != 200) {
						console.log('upload part failed');
						return;
					}
					console.log(util.inspect(res));
					if (res.header) {
						console.log(res.header.etag.replace(/\"/g, ""));
						//etags.push(res.header.etag.replace(/\"/g, ""));
						etags.push(res.header.etag);
					}
					if (i == loop_length - 1) {
						var method = 'POST';
						var new_key = "new" + key;
						var url_path_params =  '/' + key + '?uploadId=' + upload_id + '&newKey=' + new_key;
						//var etags_buf = new Buffer(etags.toString());
						var etags_str = etags.toString();
						var read_stream = new streamifier.createReadStream(etags_str);
						var finish_upload = new MultiUpload(method, url_path_params, bucket, key, read_stream, etags_str.length);
finish_upload.setHeader("X-UCloud-Hello", "1234");
finish_upload.setHeader("X-UCloud-World", "abcd");
finish_upload.setHeader("X-UCloud-Hello", "3.14");
						var client = new AuthClient(finish_upload);
						client.SendRequest(function(res) {
							if (res instanceof Error) {
								console.log(util.inspect(res));
							} else {
								console.log(util.inspect(res));
							}
						});
					} else {
						i++;
						loop_body();
					}
				}
			});	
Exemplo n.º 2
0
var streamifier = require('streamifier');

var bucket = "yellow-cup";
var key = "6M-file";
var file_path = '6M-file';

var method = 'POST';
var url_path_params = '/' + key + '?uploads';


var init_upload = new HttpRequest(method, url_path_params, bucket, key, file_path);

init_upload.setHeader("X-UCloud-Hello", "1234");
init_upload.setHeader("X-UCloud-World", "abcd");
init_upload.setHeader("X-UCloud-Hello", "3.14");
var client =  new AuthClient(init_upload);
client.SendRequest(init_response);

function init_response(res) {
	if (res instanceof Error) {
		console.log(util.inspect(res));
	} else {
		if (200 == res.statusCode) {
			console.log(util.inspect(res));
			var body = res.body;
			upload_parts(file_path, body.UploadId, body.BlkSize, body.Bucket, body.Key);
		} else {
			console.log(util.inspect(res));
		}
	}
}
Exemplo n.º 3
0
	function loop_body() {
		var start = i*blk_size;
		var end = i*blk_size + blk_size - 1;
		var stream_size = blk_size;
		if ( i === loop_length - 1 && file_size % blk_size > 0) {	
			end = i*blk_size + (file_size % blk_size);
			stream_size = file_size % blk_size;
		}	
		var options = {
			start: start,
			end: end
		};
		var method = 'PUT';
		var url_path_params = '/' + key + '?uploadId=' + upload_id + '&partNumber=' + i;
		var read_stream = fs.createReadStream(file_path, options);
		var mime_type = helper.GetMimeType(file_path);
		console.log('mime_type ' + mime_type);
		var part_upload = new MultiUpload(method, url_path_params, bucket, key, read_stream, stream_size, mime_type);
part_upload.setHeader("X-UCloud-Hello", "1234");
part_upload.setHeader("X-UCloud-World", "abcd");
part_upload.setHeader("X-UCloud-Hello", "3.14");
		var client = new AuthClient(part_upload);
		client.SendRequest(function(res) {
				if (res instanceof Error) {
					console.log(util.inspect(res));
				} else {
					if (res.statusCode != 200) {
						console.log('upload part failed');
						return;
					}
					console.log(util.inspect(res));
					if (res.header) {
						console.log(res.header.etag.replace(/\"/g, ""));
						//etags.push(res.header.etag.replace(/\"/g, ""));
						etags.push(res.header.etag);
					}
					if (i == loop_length - 1) {
						var method = 'POST';
						var new_key = "new" + key;
						var url_path_params =  '/' + key + '?uploadId=' + upload_id + '&newKey=' + new_key;
						//var etags_buf = new Buffer(etags.toString());
						var etags_str = etags.toString();
						var read_stream = new streamifier.createReadStream(etags_str);
						var finish_upload = new MultiUpload(method, url_path_params, bucket, key, read_stream, etags_str.length);
finish_upload.setHeader("X-UCloud-Hello", "1234");
finish_upload.setHeader("X-UCloud-World", "abcd");
finish_upload.setHeader("X-UCloud-Hello", "3.14");
						var client = new AuthClient(finish_upload);
						client.SendRequest(function(res) {
							if (res instanceof Error) {
								console.log(util.inspect(res));
							} else {
								console.log(util.inspect(res));
							}
						});
					} else {
						i++;
						loop_body();
					}
				}
			});	
	}
Exemplo n.º 4
0
var AuthClient = require('ufile').AuthClient;
var util = require('util');


var bucket = "yellow-cup";
var key = "test-hit-key";
var file_path = 'test.js';

var method = 'POST';
var url_path_params = '/uploadhit';


var req = new HttpRequest(method, url_path_params, bucket, key, file_path);


req.setHeader("X-UCloud-Hello", "1234");
req.setHeader("X-UCloud-World", "abcd");
req.setHeader("X-UCloud-Hello", "3.14");


var client =  new AuthClient(req);

function callback(res) {
	if (res instanceof Error) {
		console.log(util.inspect(res));
	} else {
		console.log(util.inspect(res));
	}
}
client.SendRequest(callback);