sql >> Database teknologi >  >> RDS >> Mysql

Upload billede fra iOS ved hjælp af ASIHTTPrequest

Jeg kender dit problem.. Jeg har stået over for smilar-problemet.. Du skal angive stien til billedet.. Følgende kode vil hente billedet fra stien.. hvis billedet er i dit biblioteksindeks, skal du hente vej lidt anderledes.. Prøv dette og fortæl mig det..

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"photo.jpg"]; [request setFile:[NSURL URLWithString:dataPath] forKey:@"photo"]; //IF the photo is in directory index use the following code to get the url NSString *filename = [[NSBundle mainBundle] pathForResource:@"photo" ofType:@"png"]; [request setFile:[NSURL URLWithString:filename] forKey:@"photo"];

Ok her er koden du skal skrive til UIImagePicker

- (void) imagePickerController:(UIImagePickerController *)thePicker didFinishPickingMediaWithInfo:(NSDictionary *)imageInfo 
{
    imagePicker = nil;

    UIImage *image = [imageInfo objectForKey:@"UIImagePickerControllerEditedImage"];
    image = [image roundedCornerImage:23.5 borderSize:1];




    // Get the data for the image as a JPEG
    NSData* imageData = UIImageJPEGRepresentation(image, 0.5);

    // Give a name to the file
    NSString* imageName = @"photo.png";

    // Now, we have to find the documents directory so we can save it
    // Note that you might want to save it elsewhere, like the cache directory, or something similar.
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];

    // Now we get the full path to the file
    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
    [imageData writeToFile:fullPathToFile atomically:NO];
    myPicture = imageData;
    myPicturePath = fullPathToFile;    

    // Dismissing the image picker view
    [self dismissModalViewControllerAnimated: YES];
}
 

Mens du uploader billedet, brug denne kode.. Du vil have mitBilledstien indstillet fra billedvælgeren.

Request setFile:myPicturePath forKey:@"photo"];
 

Følgende kode er til at hente billedet fra dokumentbiblioteket og sende det..

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                NSString* documentsDirectory = [paths objectAtIndex:0];

                // Now we get the full path to the file
                NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"photo.png"];
                [imageData writeToFile:fullPathToFile atomically:NO];

                [Request setFile:fullPathToFile forKey:@"photo"];
 


  1. Begrænsning af samtidige brugersessioner for et specifikt login i SQL Server

  2. MySQL IF/CASE-syntaks, der kalder forskellige SELECT-sætninger

  3. FLOT data fra MySQL via PHP?

  4. Hvordan opdaterer du hver række i tabellen i SQL ved at finde alle rækker, der er ens for en kolonne, og derefter indstille en anden kolonne lig med hinanden