Giter VIP home page Giter VIP logo

Comments (13)

bakura10 avatar bakura10 commented on June 9, 2024

Hi.

Thanks for reporting this issue. Please open a PR. I'll check this afternoon what SendGrid recommends.

Envoyé de mon iPhone

Le 9 janv. 2014 à 06:29, Stephen Bussey [email protected] a écrit :

I have been using this module with SendGrid and just started sending attachments. Oddly, my excel files were "corrupted" and easily fixed by excel, but the byte size did not match what I sent it (~100 bytes more).

I dug into the SendGridService and see this line:

$post->set('files[' . $attachment->filename . ']', $attachment->getRawContent() . ';type=' . $attachment->type);
However, this is not correct as the type is being appended to the end of the file. Removing this fixed my corruption issue. I recommend removing this line from production because ";type=whatever" is not a standard file protocol. I don't mind doing this and pull requesting.


Reply to this email directly or view it on GitHub.

from slmmail.

juriansluiman avatar juriansluiman commented on June 9, 2024

We're assuming the file type is set (see here). I think we should check if the filetype is set, because you can send attachments with and without explicit file types.

If you check the api docs you can "Send a test with attachment" and "Send a test specifying the file content type by appending ‘;type=’ to the file name". Both should be valid.

@sb8244 do you set the filetype explicitly or not? Like this:

$attachment = new MimePart(fopen('/path/to/test.pdf', 'r'));
$attachment->type = 'application/pdf';

from slmmail.

sb8244 avatar sb8244 commented on June 9, 2024

Hi Jurian,

I set the filetype explicitly by doing:

$excelPark->type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';

However, if you do not set a filetype on a Zend part, it becomes 'application/octet-stream', which would actually still be viable for an excel file.

Actually I see the bug now, "Send a [text?] specifying the file content type by appending ';type=' to the file NAME". However, SlmMail appends it to the file content.

from slmmail.

juriansluiman avatar juriansluiman commented on June 9, 2024

I have contacted the SendMail support to ask for some help with this. Meanwhile I will create a PR that will set the mime type only if it is available from the mime part object.

@sb8244 the cUrl "@" annotation is a method to embed file contents from your local file system and (as far as I know) the "@file/name.ext" is substituted with the raw file data when cUrl processes the request. In this example:

-F files[attachment.pdf][email protected];type=application/pdf

The first attachment.pdf between brackets is the file name, the second attachment.pdf should (again, afaik) be substituted with the raw file data. If you look at the raw POST data in the manual it should result in some part that looks like this:

Content-Disposition: form-data; name="files[myfile]"; filename="myfile"

Content-Type: application/octet-stream

file with stuff in it

I am not sure how to get this working, perhaps we should look at how ZF2 processes these requests.

from slmmail.

sb8244 avatar sb8244 commented on June 9, 2024

The problem I'm still seeing is that the type is getting tacked onto the
file content instead of the name. Logically this doesn't make sense because
the file contents could happen to naturally have the right content to
trigger the behavior, which the API creators at SendGrid wouldn't allow.
SendGrid docs say it needs to be on the name. I will test this on my local
copy against SendGrid to see if it works.
On Jan 15, 2014 4:51 AM, "Jurian Sluiman" [email protected] wrote:

I have contacted the SendMail support to ask for some help with this.
Meanwhile I will create a PR that will set the mime type only if it is
available from the mime part object.

@sb8244 https://github.com/sb8244 the cUrl "@" annotation is a method
to embed file contents from your local file system and (as far as I know)
the "@file/name.ext" is substituted with the raw file data when cUrl
processes the request. In this example:

-F files[attachment.pdf][email protected];type=application/pdf

The first attachment.pdf between brackets is the file name, the second
attachment.pdf should (again, afaik) be substituted with the raw file
data. If you look at the raw POST data in the manualhttp://sendgrid.com/docs/API_Reference/Web_API/mail.html#wrapper_9cb432583ceaf8911c9f978a1a09de16it should result in some part that looks like this:

Content-Disposition: form-data; name="files[myfile]"; filename="myfile"

Content-Type: application/octet-stream

file with stuff in it

I am not sure how to get this working, perhaps we should look at how ZF2
processes these requests.


Reply to this email directly or view it on GitHubhttps://github.com//issues/65#issuecomment-32347317
.

from slmmail.

juriansluiman avatar juriansluiman commented on June 9, 2024

Now I have digged through the way the http client is preparing the body of the request, I see what's happened. First, for normal post data, there aren't set any headers in the encoding of the part. However, for the files, the type of the headers is injected into the encoding method.

So, if we don't use post but files instead, I think this is going to work.

@sb8244 if you have a look later if this is the correct idea?

from slmmail.

juriansluiman avatar juriansluiman commented on June 9, 2024

Browsing the docs of Zend\Http\Client, there is also a setFileUpload() available which helps to set files for the files parameter container. In fact it exactly does what I suggested above.

from slmmail.

sb8244 avatar sb8244 commented on June 9, 2024

I think it's even less drastic. 3 lines after the post URL (on my phone so
hard to link), the files property is set. However, the set is placing the
type on content instead of the title. Literally just have to move the
content type into the file name part of that line. Definitely still use
getPost.
On Jan 15, 2014 11:05 AM, "Jurian Sluiman" [email protected] wrote:

Browsing the docs of Zend\Http\Clienthttp://zf2.readthedocs.org/en/latest/modules/zend.http.client.advanced.html#file-uploads,
there is also a setFileUpload() available which helps to set files for
the files parameter container. In fact it exactly doeshttps://github.com/zendframework/zf2/blob/master/library/Zend/Http/Client.php#L1008-L1030what I suggested above.


Reply to this email directly or view it on GitHubhttps://github.com//issues/65#issuecomment-32375196
.

from slmmail.

sb8244 avatar sb8244 commented on June 9, 2024

SendGrid files aren't sent using http files protocol, so we have to still
use post.
On Jan 15, 2014 11:09 AM, "Stephen Bussey" [email protected] wrote:

I think it's even less drastic. 3 lines after the post URL (on my phone so
hard to link), the files property is set. However, the set is placing the
type on content instead of the title. Literally just have to move the
content type into the file name part of that line. Definitely still use
getPost.
On Jan 15, 2014 11:05 AM, "Jurian Sluiman" [email protected]
wrote:

Browsing the docs of Zend\Http\Clienthttp://zf2.readthedocs.org/en/latest/modules/zend.http.client.advanced.html#file-uploads,
there is also a setFileUpload() available which helps to set files for
the files parameter container. In fact it exactly doeshttps://github.com/zendframework/zf2/blob/master/library/Zend/Http/Client.php#L1008-L1030what I suggested above.


Reply to this email directly or view it on GitHubhttps://github.com//issues/65#issuecomment-32375196
.

from slmmail.

sb8244 avatar sb8244 commented on June 9, 2024

Can the bug code at least be removed from the current version? Every time I composer update I have to reset the bug line.

from slmmail.

bakura10 avatar bakura10 commented on June 9, 2024

@juriansluiman, can you make a PR as you seem to have play with that?

from slmmail.

sb8244 avatar sb8244 commented on June 9, 2024

Can the offending code please be removed from the library? It literally serves no purpose and just causes issues for SendGrid. In no way is it working as intended, and serves no function otherwise as of now. I'm going to PR it and hope that you accept, otherwise I am going to have to fork and use a non-updating repo as my library.

from slmmail.

sb8244 avatar sb8244 commented on June 9, 2024

See #70 from here on out

from slmmail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.