I have a program: the user selects an image from his device and it is uploaded to my server.
Currently, my upload routine uploads files fine.
But I want to reescale images before uploading them.
Anyone knows how to do it? (I was planning loading-reescaling-saving-upload_saved_image but it dows not work.
Any hint how to do it?
Code: Select all
Procedure UploadFileCallback(Success, Filename.s, Result.s)
Debug "--UploadFileCallback('" + Filename + "'):"
Debug "-->"+Success+"<"
Debug "--("+Result+")"
Debug "------------------------------"
EndProcedure
Procedure UploadFile(URL.s, File, Callback)
Protected FileToUpload
Protected Filename.s
! v_filetoupload = spider.file.objects.Get(v_file).localFile;
! v_filename = v_filetoupload.name;
Debug "4-Uploading " + Filename + "..."
! var formData = new FormData();
! formData.append('fileToUpload', v_filetoupload);
! $.ajax({
! url: v_url,
! data: formData,
! contentType: false,
! processData: false,
! method: 'POST',
! type: 'POST',
! success: function(response) { v_callback(true, v_filename, response) },
! error: function(xhr, status, error) { v_callback(false, v_filename, xhr.statusText) },
! });
EndProcedure
Procedure ReadCallback(Status, Filename.s, File, Size)
If Status = #PB_Status_Loaded
Debug "2-File: " + Filename.s + " / Size: " + Size + " bytes"
UploadFile("upload.php", File, @UploadFileCallback()) ; <-- adjust the path to your upload-component!
CloseFile(File)
ElseIf Status = #PB_Status_Error
Debug "Error when loading the file: " + Filename
EndIf
EndProcedure
Procedure OpenFileRequesterCallback()
Define file.s
NewList fotos.s()
While NextSelectedFile()
AddElement (fotos())
fotos()=SelectedFileID()
total+1
Wend
Debug "1-Total images: "+total
ForEach fotos()
file=fotos()
ReadFile(#PB_Any, file, @ReadCallback(), #PB_LocalFile)
Debug "1-image: "+file
Next
EndProcedure
Procedure ChooseFileEvent() ;AQUI SE ABRE EL REQUESTER PARA ELEGIR FOTOS
OpenFileRequester("image/jpeg,image/png", @OpenFileRequesterCallback(), #PB_Requester_MultiSelection)
EndProcedure
OpenWindow(0, 0, 0, 300, 50, "WORK IN PROGRESS", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 280, 30, "Choose file(s) to upload...")
BindGadgetEvent(0, @ChooseFileEvent())