我在使用Node.js中的Multer模块上传文件时遇到一个问题。我正在解释下面的代码。
server.js:
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
tv_date= (TextView)getActivity().findViewById(R.id.tv_date);
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day);
dialog.getDatePicker().setMinDate(c.getTimeInMillis());
return dialog;
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
tv_date.setText(new StringBuilder().append(day).append("-")
.append(month+1).append("-").append(year));
date=tv_date.getText().toString();
}
}
supplierController.js:
var multer = require('multer');
var upload = multer({ dest: './upload/' });
var cpUpload = upload.fields([{ name: 'images', maxCount: 1}]);
var app=express();
var server=http.createServer(app);
var admin=require('./route/route.js');
app.post('/uploadAll',cpUpload,function(req, res, next){
console.log('fiels',req);
})
在控制台消息内部我收到以下文件数据。
var file=fileURL;
var curnum=(Math.random() * new Date().getTime()).toString(36).replace(/\./g, '');
var newPicpath=curnum+"_"+ file.name;
file.name=newPicpath;
console.log('file',file);
$scope.upload=Upload.upload({
url: '/uploadAll',
method:'POST',
data:{
images: file,
},
headers : {
'Content-Type': 'multipart/form-data'
},
}).success(function(data, status, headers, config) {
}).error(function(data, status) {
console.log('err file',data);
})
在这里你可以检查我的文件名是否包含一个随机数。当我上传文件时,文件被上传到给定的文件夹中,但是取另一个随机数(Blob
$ngfName:"vse123ertgf_1.jpg"
name:"vse123ertgf_1.jpg"
size:8607
type:"image/jpeg"
)作为其名称而没有扩展名(i.e-75149c6770ea216b5ad8aafa7698539d
)。这里我也在客户端的错误函数内得到错误响应。我正在使用i.e-.jpg or png
上传文件。我需要的文件应该使用其原始文件上传到所需的文件夹中说出它在客户端的用途。请帮我解决这个问题。