You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Fine Uploader的服务器JSON回调及额外返回数据支持的问询

Great questions about Fine Uploader! Let me break this down clearly for you:

1. Callback functions for server JSON responses in Fine Uploader

Absolutely, Fine Uploader includes dedicated callback functions to handle JSON responses from your server. The most useful ones are:

  • onComplete: Triggers when an upload finishes (regardless of success or failure). You’ll get full access to the server’s JSON response here.
  • onSuccess: Fires only when the upload is marked successful (based on the success boolean in the server’s JSON).

Here’s a quick code example showing how to use these:

var uploader = new qq.FineUploader({
    element: document.getElementById('fine-uploader'),
    request: {
        endpoint: '/your-upload-handler'
    },
    callbacks: {
        onComplete: function(id, filename, response) {
            // Log the full JSON response for debugging or processing
            console.log('Server response for', filename, ':', response);
        },
        onSuccess: function(id, filename, response) {
            // Run success-specific logic with the response data
            alert(`Upload of ${filename} completed successfully!`);
        }
    }
});
2. Handling extra data in server responses

Yes, Fine Uploader fully supports returning and processing additional data beyond the required success flag. The library only checks the success field to determine upload status—any other key-value pairs you include in your JSON response are accessible in the callback functions.

For example, if your server returns this JSON:

{
    "success": true,
    "fileId": 789,
    "previewUrl": "/uploads/preview/my-image.jpg",
    "note": "File resized to 1000px width"
}

You can extract and use that extra data like this:

callbacks: {
    onSuccess: function(id, filename, response) {
        // Grab the extra data from the response
        const fileId = response.fileId;
        const previewUrl = response.previewUrl;
        
        // Display the preview image to the user
        const previewImg = document.createElement('img');
        previewImg.src = previewUrl;
        previewImg.alt = `Preview of ${filename}`;
        document.getElementById('preview-container').appendChild(previewImg);
        
        // Store the file ID for future actions (like deleting the file later)
        console.log(`Uploaded file has ID: ${fileId}`);
    }
}

内容的提问来源于stack exchange,提问作者Renari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:37:36