gpt4 book ai didi

ios - 从解析中删除照片

转载 作者:行者123 更新时间:2023-12-01 16:42:27 25 4
gpt4 key购买 nike

我想从解析中删除照片。我该怎么办?看似一件容易的事,但我做不到,也没有真正的资料显示如何做。这是我的保存代码。我正在保存一个名为Topc的 class 。

- (void)uploadImage:(NSData *)imageData
{
PFFile *imageFile = [PFFile fileWithName:@"TopsImage.jpg" data:imageData];

HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];

// Set determinate mode
HUD.mode = MBProgressHUDModeDeterminate;
HUD.delegate = self;
HUD.labelText = @"Uploading";
[HUD show:YES];

// Save PFFile
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
//Hide determinate HUD
[HUD hide:YES];

// Show checkmark
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];

// The sample image is based on the work by http://www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];

// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;

HUD.delegate = self;

// Create a PFObject around a PFFile and associate it with the current user
PFObject *userPhoto = [PFObject objectWithClassName:@"Topc"];
[userPhoto setObject:imageFile forKey:@"imageFile"];

// Set the access control list to current user for security purposes
userPhoto.ACL = [PFACL ACLWithUser:[PFUser currentUser]];

PFUser *user = [PFUser currentUser];
[userPhoto setObject:user forKey:@"user"];

[userPhoto saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
[self refresh:nil];
}
else{
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
else{
[HUD hide:YES];
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
} progressBlock:^(int percentDone) {
// Update your progress spinner here. percentDone will be between 0 and 100.
HUD.progress = (float)percentDone/100;
}];
}

最佳答案

我在PFFile上写了一个类别,该类别允许您更新文件,这意味着删除旧文件,然后上传具有相同名称的新文件。我本来以为替换关联对象中的文件会删除旧的文件,但是并没有这样做,因为我的数据使用率正在增加。

+(void)updateFileWithName:(NSString*)name data:(NSData*)imageData completion:(void(^)(PFFile* file))completion
{
NSString* endpoint = [NSString stringWithFormat: @"https://api.parse.com/1/files/%@", name];
NSURL* url = [NSURL URLWithString:endpoint];
NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:url];

[req setHTTPMethod:@"DELETE"];
[req setValue:kParseApplicationKey forHTTPHeaderField:@"X-Parse-Application-Id"];
[req setValue:kParseMasterKey forHTTPHeaderField:@"X-Parse-Master-Key"];

NSLog(@"Updating file: %@", name);
[NSURLConnection sendAsynchronousRequest:req
queue:[NSOperationQueue currentQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"Deleted old file");
PFFile* file = [PFFile fileWithName:name data:imageData];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
NSLog(@"Saved new file");
completion(file);
}];

}];
}

您可以轻松地将其更改为通过删除 NSURLConnection完成处理程序中的块来仅删除文件

关于ios - 从解析中删除照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23042840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com