Create File and Write File

Questions and answers for designing and implementing forms in Servoy

Create File and Write File

Postby hareendra » Tue Sep 02, 2014 2:56 pm

Hi All,

I'm trying to create a file on the server. And then transfer it via ftp. The first part of the code is:
Code: Select all
var _server_file = plugins.file.createFile("myimage.jpg");
      _success = plugins.file.writeFile(_server_file, _files[0].getBytes());
      


Where _files[0] is the array containing the array of images (files);

My issue is, at the time of completion i see the status as "loading" and then "server error". The file gets transferred to the ftp location. However it is corrupted.

Any ideas?

Regards,
Hareendra
hareendra
 
Posts: 98
Joined: Wed Sep 17, 2008 11:41 am

Re: Create File and Write File

Postby ROCLASI » Tue Sep 02, 2014 3:11 pm

Hi Hareendra,

Without seeing any of the real code it's hard to say what's going on.
But do you see any errors in the Servoy log ?
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Create File and Write File

Postby hareendra » Wed Sep 03, 2014 6:50 am

Hi,

A couple of things clarified: There are no errors in the server log. I found out that the image gets successfully saved to the server location (it is NOT corrupt)
So the corruption must occure during the FTP transfer.
I am using a ftp plugin that I developed. It seems to transfer txt file successfully though. The code is as follows:
Code: Select all
var _success = true;
   
   var _file_extension = _files[0].getName().split('.')[1];
   //get FTP details
   var _fs_ftp_logins = globals.getFTPDetails('DOWNLOAD_FILES');   
   
   if(_fs_ftp_logins != null) {
      var _local_upload_path =  _fs_ftp_logins.local_folder_path + 'work/';      

      var _server_file = plugins.file.createFile(_local_upload_path + _file_save_name + "." + _file_extension);
      _success = plugins.file.writeFile(_server_file, _files[0].getBytes());
      
      application.output(_server_file);
      
   }
   else {
      _success = false;
      application.output('Could not load Master-Data: FTP Logins');
   }
   
   //upload file to FTP location
   if(_success) {
      //upload file to FTP location build folder
      _success = plugins.rp_ftp_plugin.sendFile(_fs_ftp_logins.ftp_host_name, _fs_ftp_logins.ftp_user_name, _fs_ftp_logins.ftp_password, _file_save_name+ '.' + _file_extension, _file_save_name+ '.' + _file_extension, _fs_ftp_logins.ftp_folder_path + 'build/', _local_upload_path);
      
      //move file to work folder
      if(_success) {
         _success = plugins.rp_ftp_plugin.renameFile(_fs_ftp_logins.ftp_host_name, _fs_ftp_logins.ftp_user_name, _fs_ftp_logins.ftp_password, _fs_ftp_logins.ftp_folder_path + 'build/' + _file_save_name + '.' + _file_extension, _fs_ftp_logins.ftp_folder_path + 'work/' + _file_save_name + '.' + _file_extension);
         
         if(_success) {
            plugins.file.moveFile(_local_upload_path + _file_save_name + '.' + _file_extension, _fs_ftp_logins.local_folder_path + 'proc/' + _file_save_name + '.' + _file_extension);
         }
         else {
            _success = false;
            application.output('Could not move file in FTP location');
         }
      }
      else {
         _success = false;
         application.output('Could not upload file to FTP location');
      }
   }
   
   return _success;   

Regards,
Hareendra
hareendra
 
Posts: 98
Joined: Wed Sep 17, 2008 11:41 am

Re: Create File and Write File

Postby hareendra » Wed Sep 03, 2014 8:19 am

Hi,

I just found out that it was an issue with the FTP plugin.
Then I switched to the IT2B plugin. Now it works! By the way do you have any idea why the put() method does not return a value?

Regards,
Hareendra
hareendra
 
Posts: 98
Joined: Wed Sep 17, 2008 11:41 am

Re: Create File and Write File

Postby ROCLASI » Wed Sep 03, 2014 9:21 am

Hi Hareendra,

hareendra wrote:By the way do you have any idea why the put() method does not return a value?


Good question, also Get() doesn't return a boolean to signify a successful transfer or not.
I don't know the answer to this, I suggest you ask Marcel (the author).
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium


Return to Forms

Who is online

Users browsing this forum: No registered users and 6 guests

cron