2

iPhoneから4Dサーバーに写真をアップロードしたいと思っています。具体的には、iPhoneで撮影した写真をアップロードし、4Dサーバーにアップロードして、JPEG画像としてWebFolderに保存します。4Dサーバーバージョン12および13を使用しています。ここで他の投稿を確認しましたが、4Dに適用することはできません。誰もがこれを行う方法を知っていますか?

4

3 に答える 3

2

しばらく時間がかかりましたが、ようやくこの作業を行うためのさまざまな手順に戸惑いました。私を右に置いてくれたiriphonブログ(http://www.iriphon.com/2011/11/09/ios-uploading-an-image-from-your-iphone-to-a-server/)に感謝します追跡。

これが私が使用したiOSコードです:

-(IBAction)uploadPhoto:(id)sender {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.domain.com/4DACTION/showcaseUploadPic"]
                                                            cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                        timeoutInterval:60]; 

[request setHTTPMethod:@"POST"]; 

// We need to add a header field named Content-Type with a value that tells that it's a form and also add a boundary.
// I just picked a boundary by using one from a previous trace, you can just copy/paste from the traces.
NSString *boundary = @"----WebKitFormBoundaryQkZe6RUJZ2xbzXLB";

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];

[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
// end of what we've added to the header.

// the body of the post.
NSMutableData *body = [NSMutableData data];

// Now we need to append the different data 'segments'. We first start by adding the boundary.
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

// Now append the image
// Note that the name of the form field is exactly the same as in the trace ('picBLOB' in my case).
// You can choose whatever filename you want.
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"picBLOB\" filename=\"image001.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

// We now need to tell the receiver what content type we have.
// In my case it's a jpg image. If you have a png, set it to 'image/png'.
[body appendData:[[NSString stringWithString:@"Content-Type: image/jpg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

// Now we append the actual image data.
// I use a NSData object called photoData.
[body appendData:[NSData dataWithData:photoData]];

NSLog(@"photoData size = %i",[photoData length]);

// and again the delimiting boundary.
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

// adding the body we've created to the request.
[request setHTTPBody:body];

NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"connection = %@",connection);
}

NSURLConnectionデリゲートを含めることを忘れないでください!

ブログで説明されているように、Wiresharkを使用して、必要な正確なデータを取得しました。NSDataを使用して、カメラで撮影したばかりの写真をアップロードしています。このため、私のコードは、保存されたファイルをアップロードする場合とは少し異なります。

4D(バージョン12)コードは次のとおりです。

$ba:=BLOB size(picBLOB)
C_PICTURE(imageVar)
If (Undefined(picBLOB))  // in case user tries to reload /4DACTION/WEB_Set_Limits
C_BLOB(picBLOB)
End if 

If (BLOB size(picBLOB)>0)  // did user select a file for uploading?
C_STRING(255;$fileHeader)
$offset:=0  // BLOB to text requires a variable for the offset parameter
$fileHeader:=BLOB to text(picBLOB;Mac text without length;$offset;255)
$fileNameBegin:=Position("filename=";$fileHeader)+10
For ($i;$fileNameBegin;255)
If ($fileHeader≤$i≥=Char(Double quote))
$fileNameEnd:=$i
$i:=255
End if 
End for 
$fileName:=Substring($fileHeader;$fileNameBegin;$fileNameEnd-$fileNameBegin)
$contentTypeBegin:=Position("Content-Type:";$fileHeader)+14
For ($i;$contentTypeBegin;255)
If ($fileHeader≤$i≥=Char(Carriage return))
$contentTypeEnd:=$i
$i:=255
End if 
End for 
contentType:=Substring($fileHeader;$contentTypeBegin;$contentTypeEnd-$contentTypeBegin)
DELETE FROM BLOB(picBLOB;0;$contentTypeEnd+3)

BLOB TO PICTURE(picBLOB;imageVar;"JPEG")
$FILENAME:=":WebFolder:myPhoto.jpg"
WRITE PICTURE FILE($FILENAME;imageVar;"JPEG")

End if 

4D(バージョン13)コードは次のとおりです。

C_BLOB(picBLOB)
C_PICTURE(imageVar)

WEB GET BODY PART(1;picBLOB;myPhoto)

If (BLOB size(picBLOB)>0)
BLOB TO PICTURE(picBLOB;imageVar;"JPEG")
$FILENAME:=":WebFolder:myPhoto.jpg"
WRITE PICTURE FILE($FILENAME;imageVar;"JPEG")
End if 
于 2012-06-23T15:35:50.503 に答える
1

私はこの「4Dサーバー」に特に精通していませんが、おそらくNSDataを使用して、写真をアップロードするための単純なサーバー側のPHPスクリプトが必要なようです。

あなたは正確に何を試しましたか、またはこれらの両方の分野であなたの知識の範囲はどのくらいですか?

于 2012-06-20T20:44:10.380 に答える
1

このページには、以前のバージョンでの作業手順が記載されています。iNug(4Dの開発メーリングリスト)に関する最近の投稿は、これがおそらく数週間でまだ機能することを示唆しています

4Dコミュニティが非常に小さいという理由だけで、 iNugに尋ねるより良い応答が得られます。

于 2012-06-21T23:59:13.187 に答える