用户使用移动设备拍照后是否可以更改照片的文件名?在下面的代码中,photoTaken()
函数读取图像的信息,然后调用uploadFile()
函数。是否可以在将文件发送到服务器进行处理之前重命名该文件?
HTML:
使用Javascript:
function photoTaken() {
var count = document.getElementById('inp_file').files.length;
//document.getElementById('PhotoList').innerHTML = "";
for (var index = 0; index < count; index ++)
{
var file = document.getElementById('inp_file').files[index];
var fileSize = 0;
if (file.size > 1024 * 1024) {
fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
}
else {
fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
}
document.getElementById('PhotoList').innerHTML += file.name + '|' + fileSize;
//document.getElementById('PhotoList').innerHTML += '<p>';
uploadFile(); }
function uploadFile() {
var fd = new FormData();
var count = document.getElementById('inp_file').files.length;
for (var index = 0; index < count; index ++) {
var file = document.getElementById('inp_file').files[index];
fd.append(file.name, file);
}
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", "savetofile.aspx");
xhr.send(fd);
}