Dropzone.js加载图片删除事件

时间:2017-02-16 10:28:51

标签: javascript dropzone.js

我有一个可以上传图像的dropzone。上传图像后,它们也会插入数据库中。再次打开对话框时,它必须从数据库加载图像并将它们加载到dropzone中。

目前,我有这个:

private boolean sendFCMNotification(String fcmKey,JSONObject jsonDataObject){         
        try {
            String serverKey = "AAAAZmvesa8:APA91bHdK";
            String url = "https://fcm.googleapis.com/fcm/send";
            HttpClient httpclient = HttpClients.createDefault();
            HttpPost httppost = new HttpPost(url);
            JSONObject json = new JSONObject();
            json.put("to",fcmKey);
            json.put("time_to_live",100);
            //set data object
            json.put("data",jsonDataObject);
            StringEntity stringEntity = new StringEntity(json.toString());
            httppost.setEntity(stringEntity);
            log.info("request string: "+json.toString());
            httppost.setHeader("Authorization","key="+serverKey);
            httppost.setHeader("Content-Type","application/json");
            //Execute and get the response.
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream inputStream = entity.getContent();
                try {
                    // do something useful
                    String responseStr = streamToString(inputStream);
                    JSONObject responseObject = new JSONObject(responseStr);
                    if(responseObject.getInt("success")>0) {
                        log.info("notification sent successful: ");
                        return true;
                    }else{
                        log.info("notification sent fail: ");
                        return false;
                    }
                } finally {
                    inputStream.close();
                }
            }

        }catch(Exception e){
            log.info("msg: "+e.getMessage());
        }
        return false;
    }

    private String streamToString(InputStream inputStream){
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        String string = "";
        try {
            byte[] buffer = new byte[1024];
            int length;
            while ((length = inputStream.read(buffer)) != -1) {
                result.write(buffer, 0, length);
            }
            string = result.toString("UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return string;
    }

这只是为了测试(因此大小和名称不是来自加载的图像的原因)。但是当我点击“删除文件”时,它不会触发事件。

在我创建dropzones的函数中,它显然有:

var myDropzone = Dropzone.forElement("#file_uploader");

if (data.image)
{
    var mockFile = {
        name: 'dds',
        size: 12345,
        type: 'image/' + data.extension,
        status: Dropzone.ADDED,
    };

    // Call the default addedfile event handler
    myDropzone.emit("addedfile", mockFile);

    // And optionally show the thumbnail of the file:
    myDropzone.emit("thumbnail", mockFile, 'images/' + data.image);

    myDropzone.files.push(mockFile);

    $('file_uploader').find('.dz-message').find('SPAN').css('display', 'hidden');

如果我上传新图片,则删除文件会触发该事件。如果我做了一个AJAX请求,在我预先加载图片时没有这样做。

我不知道出了什么问题。

0 个答案:

没有答案