Search code examples
iosdjangoupload

NSURL URLWithString to a relative URL


I want to upload a image (UIImage) from iOS app to Django web site.(where has forms and submit button, just like normal web page.)

So I decide to use ASIFormDataRequest for that. (I'm am new, am I doing it right?)

First,

NSURL *url = [NSURL URLWithString:@"http://someec2site/profile/album/2/upload/"];

Error: The current URL, profile/album/2/upload/, didn't match any of these.

So, I did,

NSURL *url = [NSURL URLWithString:@"http://someec2site/profile/albums/(?P<album_id>\d+)/upload/"];

ERROR: Unknown escape sequence '\d'

I have a question.

  1. Am I doing right?

  2. How can I grab a relative URL for string? (redirecting URLs based on url.py)


Solution

  • First of all Your choice of using ASI is very good for HTTP requests.

    If I am not mistaken you are trying to construct the upload urls for different album ids.

    Why don't you try this:

    NSString * urlString = [NSString stringWithFormat:@"http://someec2site/profile/album/%d/upload/",albumId];
    NSURL * url = [NSURL urlWithString:urlString];