Reputation: 25134
I am working on a Java Client Library for the recently exposed unofficial Snapchat API. As an aside, the GitHub for my library so far is here: https://github.com/hatboysam/JavaSnap
I have most requests working fine, I can log in, download images, etc. I am using UniRest for all of those requests so far because I like the simplicity of the API.
I am trying to upload media following the format outlined here: http://gibsonsec.org/snapchat/fulldisclosure/#uploading-and-sending-snaps-phupload-phsend
I have no problem generating any of the fields. The data is a byte[]
of AES-ECB encrypted data that I read from a file and ran through the specified encryption algorithm.
I have tried a few things:
Use UniRest's .field(String name, File file)
method to add the file as a parameter. I use a temporary Dile I create from the byte[]
. This gets me a 401 UNAUTHORIZED
from the server, so I think UniRest is adding some headers I don't want when I do this.
Serialize the byte[]
as a String
using the String(byte[] bytes, String encoding)
constructor with the UTF-8
encoding. This gets me a 500 SERVER ERROR
.
Not send the data
field at all, just to see what happens. This gets me a 400 BAD REQUEST
.
If you look at the upload
method in the Python library pysnap
(init.py">https://github.com/martinp/pysnap/blob/master/pysnap/init.py) you can see that what I am trying to do has been done before very simply with Python's requests
library. I can't figure out how to get the same behavior in Java.
Upvotes: 0
Views: 2067
Reputation: 234847
My understanding is that you need to encode the byte[]
data as a string using base-64 encoding. Try using javax.xml.bind.DatatypeConverter.printBase64Binary
or a third-party library for base-64.
Converting to a string using String(byte[] bytes, String encoding)
is completely different.
Upvotes: 3