Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file.save response fail #19

Closed
ohdonpiano opened this issue Sep 7, 2011 · 8 comments
Closed

file.save response fail #19

ohdonpiano opened this issue Sep 7, 2011 · 8 comments

Comments

@ohdonpiano
Copy link

When trying to upload a new file to Drupal with services 6.x 3.x,
the obtained response is not a property list and fails conversion from NSData to NSDictionary

Error Domain=DIOS-Error Code=1 "Encountered unknown tag br on line 1" UserInfo=0x11fb9d0 {NSLocalizedDescription=Encountered unknown tag br on line 1}

trying to print the received response as ASCII NSString:

Printing out response as ASCII text: è!�>�

the DIOSFile and DIOSConnect is original, not modified from github latest version.
the code for the file upload is very similar to the one that can be found on DIOSExample code.

@ohdonpiano
Copy link
Author

more info about the file: it is a quicktime .mov file of 6.9 MB of size.

Tried with a little image and the upload completes successfully, returning the fid and the url in a dictionary.

The web server that runs drupal has been tuned and php has been configured to accept POST with such parameters.

This problem could possibly be related more on Drupal code that on drupal.ios.kit...

@kylebrowning
Copy link
Owner

Is there a max upload size set?

@ohdonpiano
Copy link
Author

php has been configured in php.ini with:
upload_max_filesize 50M
post_max_size 50M
max_execution_time 800

other tests has been run with little video files of 1~2 second length. the upload works and array of fid/uri is returned from drupal. Additional tests with 3+ second length fails.
The ASIHTTPRequest progressDelegate calls the setProgress: method many times from 0.0 to 1.0, but as soon as the upload of the POST is finished, drupal returns a response that is not compatible with the NSPropertyListSerialization's propertyListFromData call.
The error returned from NSPropertyListSerialization upon de-serialization of response is really strange, as I've already written:

Error Domain=DIOS-Error Code=1 "Encountered unknown tag br on line 1" UserInfo=0x11fb9d0 {NSLocalizedDescription=Encountered unknown tag br on line 1}

recent tests has brought to similar error:

Error Domain=DIOS-Error Code=1 "Encountered unknown tag html on line 1" UserInfo=0x11fb9d0 {NSLocalizedDescription=Encountered unknown tag html on line 1}

the obvious opinion could be that drupal is responding to the post with a web page.
As long as I know, the only function that decides what is the file.create response is "function _file_resource_create($file)"
of the module "services", file_resource.inc

but why I can't print that web page code with this ObjC code?

--> in DIOSConnect's runMethod

.......
if(response != nil) {
plist = [NSPropertyListSerialization propertyListFromData:response
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorStr];
if (errorStr) {
NSError *e = [NSError errorWithDomain:@"DIOS-Error"
code:1
userInfo:[NSDictionary dictionaryWithObject:errorStr forKey:NSLocalizedDescriptionKey]];
[self setError:e];
[errorStr release];

            if ([response length] > 0) {
                NSString *responseASCII = [[NSString alloc] initWithBytes:response length:[response length] encoding:NSASCIIStringEncoding];
                NSLog(@"Printing out response as ASCII text: %@",responseASCII);
                [responseASCII release];
            } else {
                NSLog(@"Cannot print out response as ASCII text because response is 0 length.");
            }
        }
    } else {

........

this code logs, for the video of length > 3 secs

Printing out response as ASCII text: è!�>

Finally, I would like to report that I've modified DIOSFile's "fileSave" in order to put the fileDict parameters directly in the DIOSConnect's mutableArray "params" and not add them in the "params" for the key "file".
Drupal was returning errors such "No filename and no filepath specified or they are both empty." indicating that the params were not in the right place. With my modification and using little files the Drupal's response is good.

@kylebrowning
Copy link
Owner

Can you commit/fork and do a pull request for that change, or post the code her so I can get it to the others.

AS for the rest, let me investigate. Ill let you know. :(

@kylebrowning
Copy link
Owner

I havnt been able to reproduce this issue, I'm uploading videos that are 50 megs. Can you give me access to your server , or if you're not comfortable with that, give me some more reproducible issues?

@ohdonpiano
Copy link
Author

I'm sorry but I cannot give the server access since it's owned by a business company.
I recently undercover the problem, studying the choices made in drupal-ios-kit on the matter of http requests.
You're using, no matter of the need, in DIOSConnect a simple ASIHTTPRequest with a synchronous start.
I've chosen to integrate an ASIFormDataRequest when using DIOSFile and post NSData objects, because the drupal REST file.create has been modified to support multipart/form-data.
The code is sufficiently generalized to be submitted on github as a fork, but extra work is required to clean-up the code for specific project I'm working on.
I would be happy to give you and hand on introducing the use of FormDataRequest for files

@kylebrowning
Copy link
Owner

Yeah can you email me what you have for DIOS and ill just do a diff and figure out what you've changed and if its a viable option.

kyle@workhabit.com

Uploading file sizes ~6megs is probably something that happens very little but I would love to attempt to figure out why this isn't working for you.

After i see your code ill get back to you.

@kylebrowning
Copy link
Owner

This will be fixed in the next released. so I'm leaving it open, but look for 2.1 release of drupal-ios-sdk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants