2010-07-21 5 views
1

저는 정말 이상한 문제에 직면하고 있습니다. imageshack 서버에 여러 이미지를 업로드하려면 swfupload를 사용하고 있습니다. 또한 반환 된 URL을 데이터베이스에 저장하고 있습니다. imageshack에서받은 URL을받은 즉시 표시하는 방법은 무엇입니까? 업로드가 완료되면 swfupload가 URL을 반환하도록 할 수있는 방법이 있습니까?업로드 후 이미지 URL을 반환하도록 swfupload를 가져 오는 방법은 무엇입니까?

$('#swfupload-control').swfupload({ 
     upload_url: "<%= upload_url-%>", 
     file_post_name: 'photo', 
     post_params: {"authenticity_token" : "<%= form_authenticity_token %>"}, 
     file_size_limit : "100024", 
     file_types : "*.jpg;*.png;*.gif", 
     file_types_description : "Image files", 
     file_upload_limit : 5, 
     flash_url : "/flash/swfupload.swf", 
     button_image_url : '/javascripts/swfupload/XPButtonUploadText_61x22.png', 
     button_width : 62, 
     button_height : 22, 
     button_placeholder : $('#button')[0], 
     debug: false 
    }) 
     .bind('fileQueued', function(event, file){ 
      var listitem='<li id="'+file.id+'" >'+ 
       'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+ 
      '<div class="progressbar" ><div class="progress" ></div></div>'+ 
      '<p class="status" >Pending</p>'+ 
      '<span class="cancel" >&nbsp;</span>'+ 
      '</li>'; 
     $('#log').append(listitem); 
     $('li#'+file.id+' .cancel').bind('click', function(){ //Remove from queue on cancel click 
      var swfu = $.swfupload.getInstance('#swfupload-control'); 
      swfu.cancelUpload(file.id); 
      $('li#'+file.id).slideUp('fast'); 
     }); 
     // start the upload since it's queued 
     $(this).swfupload('startUpload'); 
    }) 
    .bind('fileQueueError', function(event, file, errorCode, message){ 
     alert('Size of the file '+file.name+' is greater than limit'); 
    }) 
    .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){ 
     $('#queuestatus').text('Files Selected: '+numFilesSelected+'/Queued Files: '+numFilesQueued); 
    }) 
    .bind('uploadStart', function(event, file){ 
     $('#log li#'+file.id).find('p.status').text('Uploading...'); 
     $('#log li#'+file.id).find('span.progressvalue').text('0%'); 
     $('#log li#'+file.id).find('span.cancel').hide(); 
    }) 
    .bind('uploadProgress', function(event, file, bytesLoaded){ 
     //Show Progress 
     var percentage=Math.round((bytesLoaded/file.size)*100); 
     $('#log li#'+file.id).find('div.progress').css('width', percentage+'%'); 
     $('#log li#'+file.id).find('span.progressvalue').text(percentage+'%'); 
    }) 
    .bind('uploadSuccess', function(event, file, serverData){ 
     var item=$('#log li#'+file.id), fetchedfile; 
     item.find('div.progress').css('width', '100%'); 
     item.find('span.progressvalue').text('100%'); 

     var pathtofile='<a href="'+fetchedfile+'" target="_blank" >view &raquo;</a>'; 
     item.addClass('success').find('p.status').html('Done!!! | '+pathtofile); 
    }) 
    .bind('uploadComplete', function(event, file){ 
     // upload has completed, try the next one in the queue 

     $(this).swfupload('startUpload'); 
    }) 
}); 

가 swfupload 설명서에 업로드 된 이미지 파일의 URL을 가져 오는위한 붙박이 콜백 함수가 없습니다 : 여기에 내가 업로드 한 이미지를 사용하는 코드입니다.

답변

3

오 간단했습니다. uploadSuccess는 serverData를 반환합니다!

.bind('uploadSuccess', function(event, file, serverData){ 
     var item=$('#log li#'+file.id), fetchedfile; 
     item.find('div.progress').css('width', '100%'); 
     item.find('span.progressvalue').text('100%'); 
      fetchedfile = serverData; 
     var pathtofile='<a href="'+fetchedfile+'" target="_blank" >view &raquo;</a>'; 
     item.addClass('success').find('p.status').html('Done!!! | '+pathtofile); 
    }) 
관련 문제