我已經搜索了很多關於如何將圖像從我的相機捲上傳到服務器目錄的文件,但我沒有找到任何東西!從蘋果(SimpleFTPSample),和我的代碼示例了波紋管這些代碼:如何使用FTP將圖像直接上傳到服務器目錄
- (void)_startSend:(NSString *)filePath
{
BOOL success;
NSURL * url;
CFWriteStreamRef ftpStream;
assert(filePath != nil);
assert([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
assert([filePath.pathExtension isEqual:@"png"] || [filePath.pathExtension isEqual:@"jpg"]);
assert(self.networkStream == nil); // don't tap send twice in a row!
assert(self.fileStream == nil); // ditto
// First get and check the URL.
url = [[AppDelegate sharedAppDelegate] smartURLForString:self.urlText.text];
success = (url != nil);
if (success) {
// Add the last part of the file name to the end of the URL to form the final
// URL that we're going to put to.
url = [NSMakeCollectable(
CFURLCreateCopyAppendingPathComponent(NULL, (CFURLRef) url, (CFStringRef) [filePath lastPathComponent], false)
) autorelease];
success = (url != nil);
}
// If the URL is bogus, let the user know. Otherwise kick off the connection.
if (! success) {
self.statusLabel.text = @"Invalid URL";
} else {
// Open a stream for the file we're going to send. We do not open this stream;
// NSURLConnection will do it for us.
self.fileStream = [NSInputStream inputStreamWithFileAtPath:filePath];
assert(self.fileStream != nil);
[self.fileStream open];
// Open a CFFTPStream for the URL.
ftpStream = CFWriteStreamCreateWithFTPURL(NULL, (CFURLRef) url);
assert(ftpStream != NULL);
self.networkStream = (NSOutputStream *) ftpStream;
if (self.usernameText.text.length != 0) {
#pragma unused (success) //Adding this to appease the static analyzer.
success = [self.networkStream setProperty:self.usernameText.text forKey:(id)kCFStreamPropertyFTPUserName];
assert(success);
success = [self.networkStream setProperty:self.passwordText.text forKey:(id)kCFStreamPropertyFTPPassword];
assert(success);
}
self.networkStream.delegate = self;
[self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.networkStream open];
// Have to release ftpStream to balance out the create. self.networkStream
// has retained this for our persistent use.
CFRelease(ftpStream);
// Tell the UI we're sending.
[self _sendDidStart];
}
}
這些行動進行上傳,但只是其中的圖像是我的項目中folder.So如何上傳我選擇的圖像從我的相機卷?
注意:我已經創建的UIImageView,並使其顯示從相機膠捲的圖像,作爲正常的,但如何可以上傳其顯示在UIImageView的
如何將圖像編碼爲base64,這將提供一個NSString,將該字符串發佈到服務器並通過web腳本處理該字符串以生成圖像?然後將圖像保存到您的服務器 – janusbalatbat 2012-03-10 16:08:30
您能否提供一些示例代碼或教程,我已經在這裏搜索,但我什麼也沒找到!對不起,我忘了提及我是初學者。 – Mateus 2012-03-10 16:46:11