내 카메라 롤에서 서버 디렉토리로 이미지를 업로드하는 방법을 많이 찾았지만 아무 것도 찾지 못했습니다! 단지 내가 선택한 이미지를 어떻게 업로드 할 수 있습니다 folder.So 내 프로젝트 안에있는 이미지어떻게하면 FTP를 사용하여 iOS를 직접 서버 디렉토리에 업로드 할 수 있습니까?
- (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];
}
}
그 조치가 업로드를 수행하지만, 애플 (SimpleFTPSample), 그리고 난에서 샘플 코드를 넣고 다음 코드를했다 내 카메라 롤에서?
주의 사항 : 나는 이미있는 UIImageView를 생성하고 정상적으로, 카메라 롤에서 이미지를 표시 만들었지 만, 어떻게 UIImageView에
NSString을 제공하고 문자열을 서버에 게시하고 이미지를 생성하기 위해 웹 스크립트를 통해 문자열을 처리하는 방법은 base64로 이미지를 인코딩하는 방법은 무엇입니까? 그런 다음 이미지를 서버에 저장하십시오. – janusbalatbat
샘플 코드 또는 자습서를 제공 할 수 있습니까? 여기에서 검색했지만 찾지 못했습니다! 미안하지만 초보자라는 것을 잊어 버렸습니다. – Mateus