DrupalGap icon indicating copy to clipboard operation
DrupalGap copied to clipboard

Uploading (multiple) media files from your phone

Open luxio opened this issue 8 years ago • 38 comments
trafficstars

If someone is looking for a solution to upload upload (multiple) videos, images and audio files from a smartphone he is welcome to have a look at my fork of the DG media module:

simulator screen shot 02 02 2017 13 01 35_framed simulator screen shot 02 02 2017 13 01 44_framed simulator screen shot 02 02 2017 13 08 30_framed

Currently is supports the image field, file field and the Webform Multiple File Component.

luxio avatar Feb 02 '17 12:02 luxio

See also: #816 #748 #491 #178

luxio avatar Feb 02 '17 12:02 luxio

upload audio Content type: Audio file -> is File (field type) with audio upload (widget) Content type: Audio file2 -> is Multimedia Asset (field type) with Media Browser (widget). In DrupalGap display 1st-> Audio Player only 2nd-> Media None of them seem to work. The second content type is using your Media Plugin, i suppose. Also i am using your fork of drupalgap(https://github.com/luxio/DrupalGap). When i press Upload Audio nothing happens.

xagapiou avatar Apr 05 '17 09:04 xagapiou

@rokoG: Thanks for trying.

Are the cordova-plugin-media-capture, cordova-plugin-file-transfer and cordova-plugin-dialogs enabled ?

Also i am using your fork of drupalgap(https://github.com/luxio/DrupalGap)

It should also work with the default DrupalGap version.

luxio avatar Apr 06 '17 05:04 luxio

All three plugins mentioned in your answer

are already installed. Although in config.xml are not all mentioned. <plugin name="cordova-plugin-whitelist" spec="1" />
<plugin name="cordova-plugin-console" spec="~1.0.6" />
<plugin name="cordova-plugin-device" spec="~1.1.5" />
<plugin name="cordova-plugin-dialogs" spec="~1.3.2" />
<plugin name="cordova-plugin-file" spec="~4.3.2" />
<plugin name="cordova-plugin-inappbrowser" spec="~1.7.0" />
<plugin name="cordova-plugin-network-information" spec="~1.3.2" />
<plugin name="cordova-plugin-camera" spec="~2.4.0" />
<plugin name="cordova-plugin-geolocation" spec="~2.4.2" />

Am i missing some other plugin?

thank you for your time answering. You and tyler are putting a lot of effort in it. @luxio @signalpoint

xagapiou avatar Apr 06 '17 15:04 xagapiou

Coud you share the output of

$ cordova plugin list

luxio avatar Apr 06 '17 15:04 luxio

cordova-plugin-camera 2.4.0 "Camera" cordova-plugin-compat 1.1.0 "Compat" cordova-plugin-console 1.0.6 "Console" cordova-plugin-device 1.1.5 "Device" cordova-plugin-dialogs 1.3.2 "Notification" cordova-plugin-file 4.3.2 "File" cordova-plugin-file-transfer 1.6.2 "File Transfer" cordova-plugin-geolocation 2.4.2 "Geolocation" cordova-plugin-inappbrowser 1.7.0 "InAppBrowser" cordova-plugin-media 3.0.0 "Media" cordova-plugin-media-capture 1.4.2 "Capture" cordova-plugin-network-information 1.3.2 "Network Information" cordova-plugin-whitelist 1.3.2 "Whitelist"

xagapiou avatar Apr 06 '17 15:04 xagapiou

@rokoG could you try

$ cordova plugin add cordova-plugin-media-capture cordova-plugin-file-transfer cordova-plugin-dialogs --save

and build again.

If still nothing happens when you click the button, could you share the output of the js console.

luxio avatar Apr 06 '17 15:04 luxio

Agreed, if your plugins aren't showing up in the config.xml file, then it sounds like you need to run cordova plugin save to update your project's plugin config.

signalpoint avatar Apr 06 '17 16:04 signalpoint

When adding --save parameter, indeed media plugin was added in config.xml file. But still nothing happens. Sorry but can you guide me through on how to get the javascript console output of my application? You mean guide to example.com/mobile-application and copy this js console? In /mobile-application this kind of field cannot be displayed. It displays null. No button, not anything else.

xagapiou avatar Apr 06 '17 16:04 xagapiou

WARNING: _drupalgap_form_render_element() - audiofield_field_widget_form() does not exist for the "file" form element!
WARNING: _drupalgap_form_render_element_item() - Field undefined not supported.
{"id":"edit-node-edit-field-audio-file-und-0-value","options":{"attributes":{"id":"edit-node-edit-field-audio-file-und-0-value"}},"required":1,"children":[],"title":"Audio File","default_value":""}
Object
  1. children: Array[0]
    1. length: 0
    2. __proto__:
  2. default_value: ""
  3. id: "edit-node-edit-field-audio-file-und-0-value"
  4. options: Object
    1. attributes: Object
    2. __proto__:
  5. required: 1
  6. title: "Audio File"
  7. __proto__:
media_upload - error: %o[object Object]
media_upload - error: %oNo Activity found to handle Intent { act=android.provider.MediaStore.RECORD_SOUND }

xagapiou avatar Apr 06 '17 16:04 xagapiou

i have installed https://play.google.com/store/apps/details?id=com.brightattic.soundrecorder&hl=en&rdid=com.brightattic.soundrecorder to deal with last error and it solves last error, that it cannot handle android.provider.MediaStore.RECORD_SOUND but when i try to save the uploaded sound i get

upload error source file:///storage/emulated/0/recording1593977031.m4a

xagapiou avatar Apr 06 '17 16:04 xagapiou

@rokoG

Sorry but can you guide me through on how to get the javascript console output of my application? You mean guide to example.com/mobile-application and copy this js console?

No I mean to debug your android app (either using a simulator or a real device connected via USB) using Chrome. For further information have a look Get Started with Remote Debugging Android Devices.

WARNING: _drupalgap_form_render_element() - audiofield_field_widget_form() does not exist for the "file" form element!...

These messages belong to the the first field with the audio upload widget. You can remove this field. And just the the Audi File 2 field.

As mentioned above the field should have type file, you can limit this to audio, if you only allow uploading sound file extensions (like mp4, m4a, ...).

luxio avatar Apr 06 '17 17:04 luxio

I have setup winre (http://dustint.com/post/482/getting-started-with-weinre-mobile-debugging-on-windows) and here is the console log output

get_media_success - [
MediaFile
  1. end: 0
  2. fullPath: "file:///storage/emulated/0/recording1221200004.m4a"
  3. lastModified: null
  4. lastModifiedDate: 1491498243000
  5. localURL: "cdvfile://localhost/sdcard/recording1221200004.m4a"
  6. name: "recording1221200004.m4a"
  7. size: 7545
  8. start: 0
  9. type: "audio/mpeg"
  10. __proto__:
]
:
upload error source file:///storage/emulated/0/recording1221200004.m4a

xagapiou avatar Apr 06 '17 17:04 xagapiou

So you are able to select an audio file after pressing Upload Audio?

Have you enabled the file create_raw service on your Drupal Site?

luxio avatar Apr 06 '17 17:04 luxio

Yes i am able to select an audio file. I went to admin/structure/services/list/drupalgap/resources and enabled(it was disabled). create_raw I suppose i don't have to rebuild app since it is a problem on server's behalf. So, without rebuild app,i flushed all caches inside admin/clear caches all inside drush, but still the same behaviour. The same error as above.

xagapiou avatar Apr 06 '17 17:04 xagapiou

I have tried with another node type in which allowed extensions are all kind of files and the same errors are produced when i select audio/video/image. Same error as above: upload error source & upload error target .

xagapiou avatar Apr 06 '17 18:04 xagapiou

Does the user have the permission "Save file information"? Have you checked the "Recent log messages" on the Drupal site?

luxio avatar Apr 06 '17 18:04 luxio

User role student( as the logged user in DrupalGap) has only "Save File Information" and "Get a system variable" from Services Category. Only Anonymous has not the Save File Information privilege. Recent log entries shows nothing for the specified logged in user in DG. No error. I think that upload request never reaches server. I suppose the problem lies inside DrupalGap mobile app because it says in Alert that Audio File2 Filed is required. I have never meant to flood that issue with my problem. I am continuing this in order to help others with same problem. If need be, we can meet in IRC, provide apk, provide test account credentials through IRC but i think this will not help others. I am still here if you need further information from me.

P.S. I am already more than grateful of all your help @luxio .

xagapiou avatar Apr 06 '17 19:04 xagapiou

Hi, I also decided try this module out since it might become relavant soon for one of my projects. I decided to setup clean local installation of Drupal and DrupalGap so I'm able to debug this better.

Drupal modules:

DrupalGap 7.x-1.16 File Entity 7.x-2.0-beta3 Media 7.x-2.1 Media Field 7.x-2.1 Libraries 7.x-2.3 Services 7.x-3.19 REST Server 7.x-3.19 Views 7.x-3.16 Views JSON 7.x-1.0-alpha2

DrupalGap Modules:

Media https://github.com/luxio/media

At this point the module works as desired with "Image"-field that is using the "Media browser"-widget. But the problems occur when using the "Multimedia asset"-field (which should be used if I've understood correctly?).

"Multimedia asset"-field is displayed correctly and I'm able to take the image/video/audio and it shows up inside the form before saving, but after saving the field content is disappered.

It also seems that the upload is working since I'm able to see the data inside the file system, but somehow the "link" is missing.

Example JSON output looks like this: {"nid":"","title":"test","type":"article","language":"und","body":{"und":[{"value":""}]},"field_tags":{"und":""},"field_image":{"und":[{"fid":"25"}]},"field_videofield":{"und":[{"value":"24"}]}}" I noticed that the "field_image"-field is using "fid" as key and "field_videofield" has a "value"-key, could this cause the error?

majuril avatar May 11 '17 10:05 majuril

@majuril Thank you for trying. Could you try to use a file field instead of the Multimedia asset field.

Does the media appear when viewing it in a browser?

luxio avatar May 12 '17 07:05 luxio

Well... that did the trick! 👍 Was quite sure that I tried that before and was unable to even see the widget, but I'm glad I was wrong.

Now there is one more issue occuring: After the file is saved it automatically adds "_.txt" ending to each file and saves it as a text file to the file system. I have tried to enable only "Video" file type inside File-field settings, but it's still saved as a txt-file?

majuril avatar May 12 '17 08:05 majuril

Could you check the variable services_allowed_extensions with drush vget services_allowed_extensions. It looks like the file extension is not included.

luxio avatar May 12 '17 08:05 luxio

drush vget services_allowed_extensions returns: No matching variable found. [error]

majuril avatar May 12 '17 08:05 majuril

drush vset services_allowed_extensions 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp mp3 mynewextension'

Στις Παρ, 12 Μαΐ 2017, 11:49 ο χρήστης majuril [email protected] έγραψε:

drush vget services_allowed_extensions returns: No matching variable found. [error]

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/signalpoint/DrupalGap/issues/907#issuecomment-301021042, or mute the thread https://github.com/notifications/unsubscribe-auth/AZqa43DKj0O3_jzyVFdoZeHJjuVgZX3xks5r5B0IgaJpZM4L1CEq .

xagapiou avatar May 12 '17 08:05 xagapiou

@majuril

You may have to update to the dev version of the services module or apply the patch at: https://www.drupal.org/node/2502281

luxio avatar May 12 '17 08:05 luxio

Perfect @rokoG command worked

drush vset  services_allowed_extensions jpg jpeg gif png txt doc xls pdf
ppt pps odt ods odp mp3 mynewextension

I will also try out the dev version and the patch. Thank you very much for you help!

majuril avatar May 12 '17 09:05 majuril

@luxio I have installed the all required modules and i can upload file on mobile. The issue is that when i save the node and view the node no file was uploaded. Also when i check at web there is also no file uploaded. Actually file is not saving at directory.

Important : without Media module file is saving and working correctly.

Can you guide me how can i save image in directory.

muhammadafzaal avatar Feb 20 '18 12:02 muhammadafzaal

@muhammadafzaal

Are you using an Image Field or a Media Field?

Have you checked the logs of the App and Drupal for Errors?

luxio avatar Feb 21 '18 09:02 luxio

@luxio Thank you for your quick response. I have solved this issue. Actually in default druaplgap service "create_raw" resource was not enable .

muhammadafzaal avatar Feb 21 '18 20:02 muhammadafzaal

Does this currently work with unlimited images?

jalenia avatar Mar 02 '18 06:03 jalenia