掲示板

LRUploadData to send a png in custom Liferay method

thumbnail
7年前 に Genar Codina によって更新されました。

LRUploadData to send a png in custom Liferay method

Junior Member 投稿: 28 参加年月日: 16/04/18 最新の投稿
I have a Liferay Custom method whose signature in Objective-C is:

- (NSNumber *)setImageWithCompanyId:(long long)companyId userId:(long long)userId documentId:(long long)documentId image:(LRUploadData *)image error:(NSError **)error;


This custom Liferay method has been created using the command:
./gradlew createModule -P=all
../../gradlew zip


On the other hand, I have captured an image from the camera and that image is stored in an instance of an UIImage; that is:

var image:UIImage
// then I fill the image with the photo taken from the camera
let imageData = UIImagePNGRepresentation(image) // This method converts my image to NSData
// Note: "file.png" is only a name, not a real file stored in the device. The photo is already in the "image" variable
let uploadData:LRUploadData = LRUploadData(data: image, fileName: "file.png", mimeType: "image/png", progressDelegate: nil)
let myService= LRMyService_v62(session: self.session)  // self.session contains a valid session created previously
let result:NSNumber = try myService.setImageWithCompanyId(companyId, userId:userId, documentId:documentId, image:uploadData)


However, when the method
myService.setImageWithCompanyId
is called, then the app crashes.

And the crash complains about:
Terminating app due to uncaught exception 'Upload Exception', reason: 'Set a callback to the session before uploading files'
thumbnail
7年前 に Jose M. Navarro によって更新されました。

RE: LRUploadData to send a png in custom Liferay method (回答)

Regular Member 投稿: 138 参加年月日: 14/01/24 最新の投稿
Genar Codina:

And the crash complains about:
Terminating app due to uncaught exception 'Upload Exception', reason: 'Set a callback to the session before uploading files'


Yes, when you upload files to the server you need to specify a delegate in the LRUploadData object. The delegate should conform LRFileProgressDelegate and there you will receive the upload progress

Hope it helps
thumbnail
7年前 に Alessandro Maroldi によって更新されました。

RE: LRUploadData to send a png in custom Liferay method

New Member 投稿: 5 参加年月日: 15/03/20 最新の投稿
Hi,

I'm using LRUploadData for uploading a PDF to LR custom service ( field type: java.io.File ). Always return this error
'Invalid type in JSON write (LRUploadData)'

next the code where I create the LRUploadData Object

        NSData* pdfData = [NSData dataWithContentsOfFile:_pdfPath];
        
        LRUploadData *uploadData = [[LRUploadData alloc] initWithData:pdfData
                                                             fileName:@"audioplaceholder.png"
                                                             mimeType:@"image/png"
                                                     progressDelegate:self];


I debug a little bit and I found the error its generated by this line of code in LRHttpUtil.m
+ (NSArray *)post: (LRSession *)session commands: (NSArray *)commands


NSData *body = [NSJSONSerialization dataWithJSONObject:commands options:0 error:error];


Any suggestion?

Thanks a lot for your help
thumbnail
7年前 に Alessandro Maroldi によって更新されました。

RE: LRUploadData to send a png in custom Liferay method

New Member 投稿: 5 参加年月日: 15/03/20 最新の投稿
SOLVED

There's a problem in Custom SDK Mobile Service generation, if the first parameters is not a file (LRUploadData) the command is called with :
 [self.session invoke:_command error:error];

but it has to be called like
 [self.session upload:_command error:error];
thumbnail
7年前 に Bruno Farache によって更新されました。

RE: LRUploadData to send a png in custom Liferay method

Liferay Master 投稿: 603 参加年月日: 07/05/14 最新の投稿
How does the signature of the remote method looks like? The position of file arguments in the signature shouldn't matter.
thumbnail
7年前 に Alessandro Maroldi によって更新されました。

RE: LRUploadData to send a png in custom Liferay method

New Member 投稿: 5 参加年月日: 15/03/20 最新の投稿
Hi Bruno,

you're right the answer is not in the position of the parameters but it's in the return value, if I use a return value VOID or BOOL all the methods are called with invoke. Otherwise if there's a return object the variable invokeMethod it's used by the builder.

https://github.com/liferay/liferay-mobile-sdk/blob/master/builder/src/main/resources/templates/ios/m.vm [line 81 - 87]

There is any reason why you can't return VOID with an upload service?

Thanks a lot for your help.
thumbnail
7年前 に Bruno Farache によって更新されました。

RE: LRUploadData to send a png in custom Liferay method

Liferay Master 投稿: 603 参加年月日: 07/05/14 最新の投稿
Uploads are always asynchronous . The library we use for uploads (AFNetworking) doesn't allow synchronous requests when uploading files.

Because of that, the method returns right away and doesn't wait for the response, thus it should always be void.

Take a look at the test for upload. It sets itself as the session callback and the onSuccess method is called with the response once upload has finished.
thumbnail
7年前 に Denis Signoretto によって更新されました。

RE: LRUploadData to send a png in custom Liferay method

Expert 投稿: 375 参加年月日: 09/04/21 最新の投稿
Hi Bruno,

I'm helping Alessandro investigating the issue. There was a misunderstanding. When Alessandro wrote
If I use a return value VOID or BOOL all the methods are called with invoke


he was meaning that iOS SDK Builder always generate a service that use "invoke" when remote method has return value void (or boolean). The issue arise when there is a remote service that has a java.io.File as input parameter and returns void (or boolean). In this particular case SDK Builder (for iOS) genereates a service without the "upload method invocation" but still use the "Liferay invoke method".

The workaround we have found at the moment, is changing retrun value of custom JSONWS remote service to a value different from void (or boolean).

HTH invetigating the issue.

Thanks
Denis.

P.S. Is there a particular reason why iOS SDK Builder always use invoke method when the retrun value is void? (Take a look at the iOS template file https://github.com/liferay/liferay-mobile-sdk/blob/master/builder/src/main/resources/templates/ios/m.vm at lines [81 - 87])