Attachment, content encoding

Hello

I am geting attachment data with Content().
Problem is that in mysql I can see on Headers that it shoud be base64 encoded, but when I do ContentEncoding() it says “none”.

I can see that in mysql it is type LONGBLOB, so with Content() I should get base64, right?
I am asking becuase data from Content() can ne be decoded and it looks like:

 "
01E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E\\u0014P\\u0001E
"

which for sure it is not ok. This looks like on server, which receives this request.

What I do:

my $c=0;
my %hash =();

while (my $attach = $attachments->Next) {   
       $content = $attach->Content();       
        $hash{$c}{"filename"}=$attach->Filename(); 
        $hash{$c}{"content"}=$content;
        $hash{$c}{"contentType"}=$attach->ContentType();
        $c++;
}


my $header = ['Content-Type' => 'application/json; charset=UTF-8'];
my $encoded_data = encode_json(\%hash);

my $r = HTTP::Request->new('POST', $url, $header, $encoded_data);


my $resp = $ua->request($r);
if ($resp->is_success) {
    my $message = $resp->decoded_content;
    RT::Logger->debug("Received reply: $message\n");
}

thank you!
miha

The Content() method of RT::Attachment gives you the contents of the attachment that has been decoded from Base64 encoding IF the content was encoded. In this case it doesn’t look like it was encoded, so the ContentEncoding() is returning “none”. If you need the original, potentially encoded version of the attachment, use the OriginalContent() RT::Attachment method.

The LONGBLOB data type in MySQL just means that you can store a large binary object in that field. It doesn’t imply that the data in there is stored in a particular encoding as far as MySQL is concerned.

Hmm, i tried already with OriginalContent() but I do not see any difference.

I will try now encode this when I get it via json.

hi

i tried to encode with base64 (content()) and then to encode. Name of the file is ok, but content is unreadable. Something is not ok, can you maybe help me figure it out or try to put me on right path to solve this.

Another thing:

If i do this:
RT::Logger->error(“OriginalEncoding:”, $attach->OriginalEncoding());
RT::Logger->error(“ContentEncoding:”, $attach->ContentEncoding());

I get:

Jun 6 21:47:23 localhost RT: [10784] OriginalEncoding:
Jun 6 21:47:23 localhost RT: [10784] ContentEncoding: none

tnx

I think we might need to step back and ask what you’re trying to achieve first, as I’m not sure why you’re trying to encode the content if it isn’t encoded to start with?

Hi

Yes, sure :slight_smile: what i need to do is this. When i add attachment via RT (www), I need to send this attachment to anoter system via api, this system is expacting base64 encoded attachment.

That is all.

OK, lets ignore the sending the content to another system in Base64 via that system’s API, as that’s nothing to do with RT itself. If you attach a known file to a new ticket, get that attachment back via the RT::Attachment Content() call and then save it to a new file, are the two files the same or different?