parameters) {
checkempty(appkey, baseexception.error_code_16002);
checkempty(token, baseexception.error_code_16007);
checkempty(uuid, baseexception.error_code_20016);
checkempty(blockindex, baseexception.error_code_20006);
checkempty(appsig, baseexception.error_code_10010);
if (multipartfile == null) {
throw new baseexception(baseexception.error_code_20020);// 上传文件不存在
}
long uuidl = parselong(uuid, baseexception.error_code_20016);
integer blockindexi = parseint(blockindex, baseexception.error_code_20006);
mapappmap = getauthservice().validatesigature(parameters);
accesstoken accesstoken = casutil.checkaccesstoken(token, appmap);
long uid = accesstoken.getuid();
string bucketurl = accesstoken.getbucketurl();
// 从上传目录拷贝文件到工作目录
string fileabsulutepath = null;
try {
fileabsulutepath = this.copyfile(multipartfile.getinputstream(), multipartfile.getoriginalfilename());
} catch (ioexception ioe) {
log.error(ioe.getmessage(), ioe);
throw new baseexception(baseexception.error_code_20020);// 上传文件不存在
}
file uploadedfile = new file(global.upload_temp_dir + fileabsulutepath);
checkemptyfile(uploadedfile);// file 非空验证
object rs = uploadservice.upload(uuidl, blockindexi, uid, uploadedfile, bucketurl);
sethttpstatusok(response);
return rs;
}
// todo 查看下这里是否有问题
// 上传文件非空验证
private void checkemptyfile(file file) {
if (file == null || file.getabsolutepath() == null) {
throw new baseexception(baseexception.error_code_20020);// 上传文件不存在
}
}
private string copyfile(inputstream inputstream, string filename) {
outputstream outputstream = null;
string tempfilename = null;
int pointposition = filename.lastindexof(".");
if (pointposition < 0) {// myvedio
tempfilename = uuid.randomuuid().tostring();// 94d1d2e0-9aad-4dd8-a0f6-494b0099ff26
} else {// myvedio.flv
tempfilename = uuid.randomuuid() + filename.substring(pointposition);// 94d1d2e0-9aad-4dd8-a0f6-494b0099ff26.flv
}
try {
outputstream = new fileoutputstream(global.upload_temp_dir + tempfilename);
int readbytes = 0;
byte[] buffer = new byte[10000];
while ((readbytes = inputstream.read(buffer, 0, 10000)) != -1) {
outputstream.write(buffer, 0, readbytes);
}
return tempfilename;
} catch (ioexception ioe) {
// log.error(ioe.getmessage(), ioe);
throw new baseexception(baseexception.error_code_20020);// 上传文件不存在
} finally {
if (outputstream != null) {
try {
outputstream.close();
} catch (ioexception e) {
}
}
if (inputstream != null) {
try {
inputstream.close();
} catch (ioexception e) {
}
}
}
}
@requestmapping("/core/v1/file/testserver")
@responsebody
public object testserver(httpservletresponse response) {
sethttpstatusok(response);
return global.success_response;
}
public uploadservice getuploadservice() {
return uploadservice;
}
public void setuploadservice(uploadservice uploadservice) {
this.uploadservice = uploadservice;
}
public void setauthservice(authservice authservice) {
this.authservice = authservice;
}
public authservice getauthservice() {
return authservice;
}
}