Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Deck of Cards
iduploadThumbnailCode
Card
labelObjectiveC
Code Block
borderColorGreen
langjava
titleJSON
CommunicationSingleton *CSS = [CommunicationSingleton sharedSingleton];
NSString *urlString = [[CSS getDefaultAPIURL] stringByAppendingFormat:@"%@/projects/%@/thumbnail",[CSS getSlug],currentProject.mID];
MultIPartFormCommunication *MPC = [MultIPartFormCommunication sharedSingleton];
// See the bottom of the page to see the uploadImage method[test|1.5 Code Examples#authenticationCode]
if (![MPC uploadImage:imagePlaceholder.image withExtension:@"jpeg" withFileName:@"thumbnail" ToURLString:urlString]){
[[ProjectManager sharedProjectManager] addUnUploadedThumbnailsProjectIdToList:currentProject.mID];
}
Card
labelC#

...

Deck of Cards
idgetPinListCode
Card
labelObjectiveC
Code Block
borderColorGreen
langjava
titleJSON
CommunicationSingleton *CSS = [CommunicationSingleton sharedSingleton];
    //create issue request:
    NSMutableURLRequest *pinListRequest;
    pinListRequest = [[NSMutableURLRequest alloc] init];
    
    NSString *urlStringForIssue = [NSString stringWithFormat:@"%@%@/issues/%@/pins",
                                   [CSS getDefaultAPIURL],
                                   [CSS getSlug],
                                   issueid];
    DLog(@"%@",urlStringForIssue);
    [pinListRequest setURL:[NSURL URLWithString:urlStringForIssue]];
    [pinListRequest setHTTPMethod:@"GET"];
    [pinListRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [pinListRequest setValue:[CSS getAuthorization] forHTTPHeaderField:@"Authorization"];
    
    NSHTTPURLResponse *responseHTTPForPinList;
    NSError *error;
    
    NSData *rawPinList = [NSURLConnection sendSynchronousRequest:pinListRequest returningResponse:&responseHTTPForPinList error:&error];
    [pinListRequest release];
    
    if ([responseHTTPForPinList statusCode] == 200) {
        NSMutableArray *pinList = [NSJSONSerialization JSONObjectWithData:rawPinList options:NSJSONReadingMutableContainers error:&error];
        return  pinList;
    }else{
        return NULL;
    }
Card
labelC#

...

Deck of Cards
idcreateAttachmentForIssueCode
Card
labelObjectiveC
Code Block
borderColorGreen
langjava
titleJSON
NSString *attachmentURL = [[CSS getDefaultAPIURL] stringByAppendingFormat:@"%@/issues/%@/attachments", [CSS getSlug],currentIssueId];
	MultIPartFormCommunication *MPC = [MultIPartFormCommunication sharedSingleton];
	NSString *imageName = [NSString stringWithFormat:@"issueImage%f",[[NSDate date] timeIntervalSince1970]];
        // See the bottom of the page to see the uploadImage method
	if ([MPC uploadImage:issueImage withExtension:@"jpeg" withFileName:imageName ToURLString:attachmentURL]){
                //succesful uploading
            }else{
                //unsuccesful uploading store the issue image in a list:
            }

Card
labelC#

...

Deck of Cards
idgetAttachmentListFromIssueCode
Card
labelObjectiveC
Code Block
borderColorGreen
langjava
titleJSON
CommunicationSingleton *CSS = [CommunicationSingleton sharedSingleton];
    NSMutableURLRequest *attachmentsRequest;
    attachmentsRequest = [[NSMutableURLRequest alloc] init];
    
    NSString *urlStringForIssue = [NSString stringWithFormat:@"%@%@/issues/%@/attachments",
                                   [CSS getDefaultAPIURL],
                                   [CSS getSlug],
                                   issueid];
    DLog(@"%@",urlStringForIssue);
    [attachmentsRequest setURL:[NSURL URLWithString:urlStringForIssue]];
    [attachmentsRequest setHTTPMethod:@"GET"];
    [attachmentsRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [attachmentsRequest setValue:[CSS getAuthorization] forHTTPHeaderField:@"Authorization"];
    
    NSHTTPURLResponse *responseHTTPForAttachments;
    NSError *error;

    
    NSDataNSData *rawAttachmentsList = [NSURLConnection sendSynchronousRequest:attachmentsRequest returningResponse:&responseHTTPForAttachments error:&error];
    [attachmentsRequest release];
    
    if ([responseHTTPForAttachments statusCode] == 200) {
        NSMutableArray *attachmentsList = [NSJSONSerialization JSONObjectWithData:rawAttachmentsList options:NSJSONReadingMutableContainers error:&error];
        if ([attachmentsList count] > 0) {
            return attachmentsList;
        }else{
            return NULL;
        }
    }else{
        return NULL;
    }
Card
labelC#


Anchor
uploadImageCode
uploadImageCode

Get the attachment list from the issue

Deck of Cards
iduploadImageCode
Card
labelObjectiveC
Code Block
borderColorGreen
langjava
titleJSON

- (BOOL)uploadImage:(UIImage*)image withExtension:(NSString*)ext withFileName:(NSString*)fileName ToURLString:(NSString*)urlString{
    
    CommunicationSingleton *CSS = [CommunicationSingleton sharedSingleton];
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    // Method
    [request setHTTPMethod:@"POST"];
    
    // Set headers
    NSString *boundary = @"AaB03x";
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
    
    [request setValue:[CSS getAuthorization] forHTTPHeaderField:@"Authorization"];
    [request addValue:contentType forHTTPHeaderField:@"Content-Type"];
    
    // FORM
    NSData *dataForTestImage = UIImageJPEGRepresentation(image, 1.0);
    NSMutableData *body = [NSMutableData data];
    
    [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@.%@\"\r\n", fileName,ext] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:dataForTestImage];
    
    // fileName
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"fileName\"\r\n\r\n%@.%@", fileName,ext] dataUsingEncoding:NSUTF8StringEncoding]];
    
    // type
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"type\"\r\n\r\nimage/%@", ext] dataUsingEncoding:NSUTF8StringEncoding]];
    
    // size
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"size\"\r\n\r\n%d", [dataForTestImage length]] dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    // objectIds
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"objectIds\"\r\n\r\n%@", @""] 
dataUsingEncoding:NSUTF8StringEncoding]];
    
    // End
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
    [request setHTTPBody:body];
    
    NSHTTPURLResponse* response;
    NSError* err;
    [NSURLConnection sendSynchronousRequest:request
                          returningResponse:&response
                                      error:&err];
    
    if ([response statusCode] == 201) {
        return true;
    }else{
        return false;
    }
}