How do i retrieve and save the attachment sent to me via a form post with Mailgun's POST
The following the some of the parameters
attachment-1
{:filename=>"crabby.gif", :type=>"image/gif", :name=>"attachment-1", :tempfile=>#<Tempfile:/tmp/RackMultipart20140707-2-slsrkh>, :head=>"Content-Disposition: form-data; name=\"attachment-1\"; filename=\"crabby.gif\"\r\nContent-Type: image/gif\r\nContent-Length: 2785\r\n"}
attachment-2
{:filename=>"attached_файл.txt", :type=>"text/plain", :name=>"attachment-2", :tempfile=>#<Tempfile:/tmp/RackMultipart20140707-2-sudxuf>, :head=>"Content-Disposition: form-data; name=\"attachment-2\"; filename=\"attached_файл.txt\"\r\nContent-Type: text/plain\r\nContent-Length: 32\r\n"}
Content-Type
multipart/mixed; boundary="------------020601070403020003080006"
So I know this is a year late, but I had the same problem and figured out how to download the attachments. The files in the post are in stored in the environmental variable $_FILES. The information for each file will look something like:
The path to the file is stored in
tmp_name
, so in this case,/tmp/php8zhmlU
is the full path to the file.move_uploaded_file
will overwrite any existing files! To download all the attachments from thePOST
I wrote a function:Documentation for this top can be found here.
if you json decoded list of attachments is $files, you can do
to download every attachment