简体   繁体   中英

How to attach files, which were saved in DriveHQ in Rails mailer?

In my application i have a file upload option. The uploaded files used to saved in DriveHQ ftp server. After uploading i want to send a mail to the admin with the uploaded file as attachment.

I tried as follows

 uri = URI::FTP.build(['username:password', 'ftp.drivehq.com', nil,"\\My Documents\\#{17}\\Fitness.txt", 'i'])

And in the mailer:

 attachments['image'] = {mime_type: 'text/plain',content: File.read(uri)}

But its not working. it was returning error as

 bad component(expected relative path component): \My Documents\17\Fitness.txt;type=i

I guess you're using the API in a wrong way.

You need to download the file, and yes you do it by creating an URI to the FTP server, but then you need to download the file to a temporary directory.

After that, in your mailer you read that file.

Remember since File is a subclass of IO and it does not have the read method, when you invoke File.read, you are actually calling IO.read .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM