CPImage and Basic Auth

37 views
Skip to first unread message

Todd Freese

unread,
Oct 15, 2015, 5:55:39 PM10/15/15
to Cappuccino & Objective-J
I create an CPImage using initWithContentsOfFile and pass it a URL to a static image.

Now, I need to get an CPImage from a server that requires HTTP Basic Auth. How do I do this? Is there a way to set HTTP header fields for the call to get the image in CPImage?

Todd

Aparajita

unread,
Oct 15, 2015, 6:11:47 PM10/15/15
to Cappuccino & Objective-J

Todd Freese

unread,
Oct 15, 2015, 6:24:32 PM10/15/15
to Cappuccino & Objective-J
So I understand how to do basic auth.

My question is in a call like this:

proxy = [[CPImage alloc] initWithContentsOfFile:@"https://server.foobar.com/myImage"];

How do I add the http headers? Is there a way to access the underlying CPURLRequest that CPImage is using?

Todd

Aparajita

unread,
Oct 15, 2015, 8:05:25 PM10/15/15
to Cappuccino & Objective-J
Make a CPURLRequest yourself to get the data with the correct header, then use `CPImage -initWithData` to create the image.

Todd Freese

unread,
Oct 16, 2015, 12:52:55 PM10/16/15
to Cappuccino & Objective-J
Almost there...

Is there a way to get CPData from the CPURLConnection? Or do I just make a CPData from the string return?

This is what I have so far:

- (void)connection:(CPJSONConnection)aConnection didReceiveData:(CPString)data
{
    var returnCode = [aConnection _HTTPRequest].status();
    if (returnCode == 200) {
        var imageData = [[CPData alloc] initWithRawString:data];
proxy = [[CPImage alloc] initWithData:imageData];
        CPLog(proxy)
     }
}

My log statement returns:

<CPImage 0x008d3b> {
   filename: "data:image/png;base64,///9/QAQSk...RK//03///9",
   size: { width:-1, height:-1 }
}

Aparajita

unread,
Oct 16, 2015, 1:14:04 PM10/16/15
to Cappuccino & Objective-J
That isn't working?

Todd Freese

unread,
Oct 16, 2015, 1:57:27 PM10/16/15
to Cappuccino & Objective-J
No, it seems to be making an image with a size of -1, -1.

Todd

Todd Freese

unread,
Oct 16, 2015, 2:01:20 PM10/16/15
to Cappuccino & Objective-J
But if I call setSize on it, I see an image. But I don't know the correct sizes of the images.

Todd

Aparajita

unread,
Oct 16, 2015, 4:03:08 PM10/16/15
to Cappuccino & Objective-J
That's normal, the size isn't set until the next pass through the event loop. You can either subscribe to the CPImageDidLoadNotification on the image, or set a delegate and implement -imageDidLoad:(CPImage)image. In either of those handlers use [image size] to get the size.

Todd Freese

unread,
Oct 16, 2015, 4:27:26 PM10/16/15
to Cappuccino & Objective-J
I was wrong about it working when setting the size.

Do I need to tell CPImage what type of image it is? Or is that in the data?

T

Aparajita

unread,
Oct 16, 2015, 4:45:38 PM10/16/15
to Cappuccino & Objective-J
It should be in the data.
Reply all
Reply to author
Forward
0 new messages