B4A Library CloudRail - CloudStorage (Dropbox, GoogleDrive, OneDrive and Box) Payment (PayPal, Stripe), POI

This is a Wrapper for the CloudStorage API from CloudRail.

At this point of development there is no Social-module wrapped. CloudRail does support more than just the CloudStorage-Api. But it was this i was interested in so i wrote the wrap for them...

I leave it up to the community to extend the library; i´ll share the written JAVA-Code

Requirements:
- B4A 6+ as the library is using a aar
- Account at CloudRail. Note that they also provide free subscription.
https://cloudrail.com/cloudrail-pricing/
- The file cloudrail-si.aar which can be downloaded here.
- An ClientID and Secret from the content-provider you want to use.
Dropbox
GoogleDrive
OneDrive
Box

Installation: Copy all three files from the library zip to your additional libs folder.
CloudRail.xml, CloudRail.jar and cloudrail-si.aar



Example-Code (for Dropbox)

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim dropbox As Dropbox
    Dim cr As CloudRail
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    cr.Initialize("CloudRail","cloudrailid")
End Sub
Sub CloudRail_Ready(Success As Boolean)
    Log($"CloudRail_Ready(${Success})"$)
    If Success Then
        'dropbox.Initialize("Dropbox","client id","client secret")
    End If
End Sub

B4X:
Sub Dropbox_Ready(Success As Boolean)
    Log($"Dropbox_Ready(${Success})"$)
    dropbox.getChildren("/")
    dropbox.getChildren("/B4A")
    dropbox.checkAllocation
    dropbox.download("/B4A/MaterialDesign-Webfont-master.zip",rp.GetSafeDirDefaultExternal("Downloads"),"MaterialWebfont.zip")
End Sub
Sub Dropbox_DownloadFinished(success As Boolean, info As String, filePath As String, destPath As String, destFile As String)
    Log($"Dropbox_DownloadFinished(${destFile}->${success},${destFile},${filePath})"$)
End Sub
Sub Dropbox_Allocation(alloc As Object)
    Log($"Dropbox_Allocation()"$)
    If alloc <> Null Then
        Dim sa As SpaceAllocation = alloc
        Log($"${sa.Used} Used"$)
        Log($"${sa.Total} Total"$)
    End If
End Sub
Sub Dropbox_MetaData(path As String, meta As Object)
    Log($"Dropbox_MetaData(${path},${meta})"$)
End Sub
Sub Dropbox_Login(Success As Boolean)
    Log($"Dropbox_Login(${Success})"$)
End Sub
Sub Dropbox_Children(folder As List, files As List)
    Log($"Dropbox_Children()"$)
    If folder <> Null Then
        Log($"folder: ${folder.Size}"$)
    End If
    If files <> Null Then
        Log($"files: ${files.Size}"$)
    End If
    'Log($"Dropbox_Children(${folder})"$)
End Sub

CloudRail
Author:
DonManfred (wrapper)
Version: 1.5
CloudRail
Events:

  • Ready (Success As Boolean)
Methods:
  • validateKey As void
  • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String, AppKey As java.lang.String) As void
Permissions:
  • android.permission.ACCESS_NETWORK_STATE
  • android.permission.INTERNET
  • android.permission.READ_EXTERNAL_STORAGE
  • android.permission.WRITE_EXTERNAL_STORAGE
Properties:
  • AppKey As java.lang.String

Business CloudStorage:
AmazonS3
Backblaze
GoogleCloudPlatform
MicrosoftAzure
Rackspace
OneDriveBusiness


Cloud Storage:
Box
Google-Drive
Dropbox
Egnyte
OneDrive









SpaceAllocation
Methods:

  • hashCode As int
  • equals (o As java.lang.Object) As boolean
  • toString As java.lang.String
  • IsInitialized As boolean
  • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String, space As com.cloudrail.si.types.SpaceAllocation) As void
Properties:
  • Used As java.lang.Long
  • Total As java.lang.Long
 

Attachments

  • CloudRailV1.51.zip
    189.7 KB · Views: 514
  • CloudRailV1.52.zip
    188.7 KB · Views: 529
  • CloudRailV1.54.zip
    188.8 KB · Views: 727
  • cloudrail-si.zip
    453.7 KB · Views: 701
  • cloudrailEx.zip
    8 KB · Views: 688
Last edited:

Husam

Member
Licensed User
@DonManfred

I tried 0 and also the correct size of the file. Nothing seems to work when it comes to uploading files from RootExrternal or DefaultExternal.
B4X:
dropbox.upload(File.DirRootExternal & "/HHE/DG1100216100816.txt","/Import",0,True)  'no go

Could you also address why I can download from DefaultExternal but not from RootExternal. You might want to test it for yourself.

add " DG1100216100816.txt " file name to destPath , it should work
B4X:
dropbox.upload(File.DirRootExternal & "/HHE/DG1100216100816.txt","/Import/DG1100216100816.txt",0,True)
 

DonManfred

Expert
Licensed User
Longtime User
https://github.com/CloudRail/cloudr...sage#interfaces-cloudstorage-functions-upload
/**
* Uploads a file to a cloud storage, throws an exception if the path is invalid,
* the parent path does not exist, the stream is null or the size negative.
*
* @param filePath The path where to store the file from the root folder and including the name, e.g /myFolder/myFile.jpg.
* @param stream A stream from which the file can be read.
* @param size The size in bytes of the data that can be read from the stream.
* @param overwrite If true, an existing file with the same path will be overwritten (its contents updated),
* if false the presence of a file with the same name will cause an exception.
*/
void upload(String filePath, InputStream stream, long size, boolean overwrite);
 

Mahares

Expert
Licensed User
Longtime User
When I switched from a device with OS 4.2.2 to a device with OS 6.0.1, the upload and download work very well. But, with OS 4.2.2, I was constantly denied. Here is the error on 4.2.2:
B4X:
com.cloudrail.si.exceptions.HttpException: {"error_description": "code has already been used", "error": "invalid_grant"}
 

Mahares

Expert
Licensed User
Longtime User
Downloading multiple files from a given Dropbox subfolder gives me this error:
'Object reference not set to an instance of an object'
Here is my code:
B4X:
Dim MyExport As String= "/Export"
Sub Dropbox_Ready(Success As Boolean)
    Log($"Dropbox_Ready(${Success})"$)
    dropbox.getChildren(MyExport)
    Dim MyList As List
    MyList.Initialize
    For Each meta As CloudMetaData In dropbox.getChildren(MyExport)  '<--- Here is the problem
        MyList.Add(meta.name)
    Next
   
    For Each f As String In MyList
        If f.EndsWith(".tab") Then
            dropbox.download(MyExport & "/" & f, File.DirRootExternal,  "/" & f    )
        End If
    Next
End Sub
I appreciate your help if you can.
 

DonManfred

Expert
Licensed User
Longtime User
getChildren is an async task and it raises an event where you get the result. eventname_children
Not that getChildren does not have a return value. so the code
B4X:
 For Each meta As CloudMetaData In dropbox.getChildren(MyExport)
will not work

Built your downloadlist inside this event
 

Mahares

Expert
Licensed User
Longtime User
I am trying to download a few files from google drive to a folder in the device using this powerful library. But, every time the app runs, the app stops and the screen requests permission like this before continuing:
‘Name of the project that created the client ID’ would like to have offline access:
Below the message are 2 buttons: one says:’ Deny’ and the other ‘Allow’. Obviously I click the ‘Allow’ button. The app continues, downloads the files occasionally but crashes most of the time.

The error despite Google Drive API being enabled when I created the client ID and secret says:
com.cloudrail.si.exceptions.HttpException: Forbidden - Make sure that the Google Drive API is enabled.

Has anyone including @DonManfred tried the Google Drive portion of this lib in a project and can share their findings.

Thank you
 

Paulsche

Well-Known Member
Licensed User
Longtime User
Is there a sample code for upload and download a file to/from Google Drive?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Is there a sample code for upload and download a file to/from Google Drive?
i did only a few (very few) tests with google drive.

B4X:
    drive.upload(File.Combine(File.DirRootExternal,"WhatsAppSetup.exe"),"/Cloudrail/WhatsAppSetup.exe",File.Size(File.DirRootExternal,"WhatsAppSetup.exe"), True)
    Drive.download("/B4A/MaterialDesign-Webfont-master.zip",rp.GetSafeDirDefaultExternal("Downloads"),"MaterialWebfont.zip")

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim dropbox As Dropbox
    Dim drive As GoogleDrive
    Dim cr As CloudRail
    Dim places As GooglePlaces
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
   If Permission = rp.PERMISSION_WRITE_EXTERNAL_STORAGE Then
   End If
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    cr.Initialize("CloudRail","xxxx")
End Sub
Sub CloudRail_Ready(Success As Boolean)
    Log($"CloudRail_Ready(${Success})"$)
    If Success Then
        'dropbox.Initialize("Dropbox","yyyy","zzzz")
        drive.Initialize("Drive","0000000","11111111")
        'places.Initialize("Places","222222")
        'places.NearbyPOIs(49.4557091, 8.5279138, 3000, "Restaurant", Null)
    End If
End Sub
Sub Drive_Ready(Success As Boolean)
    Log($"Drive_Ready(${Success})"$)   
    drive.getChildren("/Cloudrail")
    'drive.checkAllocation
   
    'drive.upload(File.Combine(File.DirRootExternal,"CloudRailV1.0.zip"),"/Cloudrail/CloudRailV1.0.zip",File.Size(File.DirRootExternal,"CloudRailV1.0.zip"), True)
    'drive.upload(File.Combine(File.DirRootExternal,"CloudRailV1.1.zip"),"/Cloudrail/CloudRailV1.1.zip",File.Size(File.DirRootExternal,"CloudRailV1.1.zip"), True)

    'drive.upload(File.Combine(File.DirRootExternal,"WhatsAppSetup.exe"),"/Cloudrail/WhatsAppSetup.exe",File.Size(File.DirRootExternal,"WhatsAppSetup.exe"), True)
    'Drive.download("/B4A/MaterialDesign-Webfont-master.zip",rp.GetSafeDirDefaultExternal("Downloads"),"MaterialWebfont.zip")
   
   
    'Drive.getMetadata("/b4a")
End Sub
Sub Drive_DownloadFinished(success As Boolean, info As String, filePath As String, destPath As String, destFile As String)
    Log($"Drive_DownloadFinished(${destFile}->${success},${destFile},${filePath})"$)   
End Sub
Sub Drive_UploadFinished(destPath As String, info As String, success As Boolean)
    Log($"${destPath}, ${info}, ${success}"$)
End Sub
 

Paulsche

Well-Known Member
Licensed User
Longtime User
Ok, upload a file works. But when enable CloudRail, the Lib Geocoder does not work anymore,
Where I can see the location with the name and the street.
 

Paulsche

Well-Known Member
Licensed User
Longtime User
I guess it is because of the same objectnames... both libs does have a Address object...

yes I believe that too. I do not know if I can replace the CloudRail the geocoder. Actually, I've got Dropbox, GoogleDrive already through another Lib,
LibGoogleDrive, my problem with this is that I can not upload a large file over 50MB in Google Drive, because there is a memory error, which does not come with CloudRail.
 

Paulsche

Well-Known Member
Licensed User
Longtime User
When connecting to GoogleDrive every time the confirmation for offline access, can not save it?
 

Paulsche

Well-Known Member
Licensed User
Longtime User
I did not understand.
Vielleicht zusätzlich in deutsch?
OK, die Bestätigung für den Offline-Zugriff wird nicht gespeichert
und bei jedem Connect neu abgefragt, siehe Anhang.
Wie kann man diese Bestätigung speichern, so dass sie nur 1 x abgefragt wird ?

GD.png
 
Top