上传图片到bmob
如何上传图片到bmob,有没有demo
如何上传图片到bmob,有没有demo
2014-12-30
<!doctype html>
<head>
<meta charset="utf-8">
<title>My Bmob App</title>
<meta name="description" content="My Bmob App">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/styles.css">
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="bmob.js"></script>
</head>
<body>
<input type="file" id="profilePhotoFileUpload" >
<input type="button" onclick='uploadfile()'>upload</input>
<div id="imagelist">
<script type="text/javascript">
//Bmob.initialize("Application ID", "REST API Key");
Bmob.initialize("", "");
function uploadfile(){
var fileUploadControl = $("#profilePhotoFileUpload")[0];
if (fileUploadControl.files.length > 0) {
var fileObjs = fileUploadControl.files[0];
var file = new Bmob.File(fileObjs.name, fileObjs);
//上传文件
file.save().then(function(obj) {
var PhotoList = Bmob.Object.extend("test1");
var photoList = new PhotoList();
//把返回的文件插入到文件列表
var image=$("<image src='"+obj.url()+"'/>");
var imagelist =$("#imagelist")
imagelist.append(image);
var url =obj.url();
//把文件的url保存在表“PhotoList”的字段“url” 中
photoList.set("url",obj.url());
Bmob.Image.thumbnail({"image":obj.url(),"mode":0,"quality":100,"width":100,"outType":0}
).then(function(obj) {
alert("filename:"+obj.filename); //
alert("url:"+obj.url); //
photoList.set("thumbnailurl",obj.url);
photoList.save();
var imagetemp=$("<image src='http:\//file.bmob.cn/"+obj.url+"'/>");
imagelist.append(imagetemp);
});
}, function(error) {
// the save failed.
});
}
}
</script>
</body>
</html>
举报