English 中文(简体)
图像数据要求上载图像,无档案(无)
原标题:asiformdatarequest upload image,No file exists at (null)

I use asiformdatarequest framework to upload images,The code like this:

 NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path1=[paths objectAtIndex:0];
    NSString *filename=[path1 stringByAppendingPathComponent:@"logo.png"];  
    NSLog(@"image path = %@",filename);
    [request setFile:[NSURL URLWithString:filename] forKey:@"avatar"];
    [request startSynchronous];

我的记录:

image path = /Users/tanlusheng/Library/Application Support/iPhone Simulator/5.1/Applications/5473E6FF-0D3A-48CD-8728-0219CF25BC80/Documents/logo.png
Error Domain=ASIHTTPRequestErrorDomain Code=6 "No file exists at (null)" UserInfo=0x6b4c610 {NSLocalizedDescription=No file exists at (null)}

我在我的项目中增加了一个形象。 但它为什么不能找到档案? 我坐在模拟器上。

问题回答

当你再次试图传播图像时,你再次试图从应用<条码>文件目录中传播图像,而不是主要障碍。 除非你将图像明确列入目录(你最有可能通过代码制作),否则将不存在。

相反:

NSString *filename = [[NSBundle mainBundle] pathForResource:@"logo" ofType:@"png"];  
[request setFile:[NSURL URLWithString:filename] forKey:@"avatar"];
[request setDelegate:self]; //Make sure this class receives request alerts
[request setDidFinishSelector:@selector(someMethod:)]; //Which method to call when finished
[request startAsynchronous];

Note I ve also changed the request to start asynchronously. You really don t want to upload synchronously or your app will stop executing until the request is finished. I ve also added the self delegation and a selector for when the request finishes.

之后,你可以在此处理已完成的问题:

- (void)someMethod:(ASIHTTPRequest *)request
{
    NSString *response = [request responseString];
    NSLog(@"%@", response);
}

如果你仍然犯了错误,则确保图像Target Members。 为此,在X条码中选择你的形象,并确保在右边的Target Membersip下打上小盒子。 这将确保图像在构造时成为你应用的一部分。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签