cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Transfer file from TW Server to remote JavaSDK

SOLVED
ses
Newbie

Transfer file from TW Server to remote JavaSDK

Hi Experts, Coluld you pls guide me on steps for

Transfer a file(zip) from TW Server to remote JavaSDK

I tried something, but not succeeded, using Copy service.

With that I cud achieve only copy a file between two folders, both on the TW Server.

My need is to copy a file from TW Server to remote JavaSDK.

Thanks

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Transfer file from TW Server to remote JavaSDK

Sujith,

You are correct in using the Copy service, but there are a couple of things you need to make sure are configured correctly:

  • A FileRepository Thing has been created on the ThingWorx server - in the following code sample (from a custom service) I've named my FileRepository "TestingRepo"
    • sourceRepo is the name of my FileRepository in ThingWorx
    • targetRepo is the name of the Edge Thing defined in the Java SDK

var params = {

  async: false /* BOOLEAN */,

  sourceRepo: "TestingRepo" /* STRING */,

  targetRepo: "FileTransferExample" /* STRING */,

  targetFile: "werd_2014.gif" /* STRING */,

  targetPath: "in" /* STRING */,

  sourceFile: "werd_2014.gif" /* STRING */,

  sourcePath: "Meghan" /* STRING */,

  timeout: undefined /* INTEGER */

};

// result: INFOTABLE dataShape: FileTransferJob

var result = Subsystems["FileTransferSubsystem"].Copy(params);


  • The following is the entire Java file (provided in the Java SDK download) that sets up Virtual Directories for a file transfer.
    • If you look at the custom service above to see that we are referencing the targetPath for a directory that is defined in the Java class.


package com.thingworx.javatransfer;

import com.thingworx.communications.client.ClientConfigurator;

import com.thingworx.communications.client.ConnectedThingClient;

import com.thingworx.communications.client.things.filetransfer.FileTransferVirtualThing;

public class FileTransferExample {

  // Substitute your thing name here

  private static final String ThingName = "FileTransferExample";

  public static void main(String[] args) {

  // Create a client config

  ClientConfigurator config = new ClientConfigurator();

  // Basic configuration. See SimpleClient.java for additional info.

  config.setUri("wss://localhost:8443/Thingworx/WS");

  config.setAppKey("8737c3b9-bc65-4ac8-8990-64b565487cd3");

  config.ignoreSSLErrors(true);

  try {

  ConnectedThingClient client = new ConnectedThingClient(config);

  FileTransferVirtualThing myThing = new FileTransferVirtualThing(ThingName, "File Transfer Example", client);

  // Add two virtual directories that will act as the root directories in this

  // application's virtual file system.

  myThing.addVirtualDirectory("in",  "/home/meg/files/in");

  myThing.addVirtualDirectory("out", "/home/meg/files/out");

  client.bindThing(myThing);

  client.start();

  while(!client.isShutdown()) {

  Thread.sleep(5000);

  }

  } catch(Exception e) {

  e.printStackTrace();

  }

  }

}

Let me know if you have any further questions.

Meghan

7 REPLIES 7

Re: Transfer file from TW Server to remote JavaSDK

Sujith,

You are correct in using the Copy service, but there are a couple of things you need to make sure are configured correctly:

  • A FileRepository Thing has been created on the ThingWorx server - in the following code sample (from a custom service) I've named my FileRepository "TestingRepo"
    • sourceRepo is the name of my FileRepository in ThingWorx
    • targetRepo is the name of the Edge Thing defined in the Java SDK

var params = {

  async: false /* BOOLEAN */,

  sourceRepo: "TestingRepo" /* STRING */,

  targetRepo: "FileTransferExample" /* STRING */,

  targetFile: "werd_2014.gif" /* STRING */,

  targetPath: "in" /* STRING */,

  sourceFile: "werd_2014.gif" /* STRING */,

  sourcePath: "Meghan" /* STRING */,

  timeout: undefined /* INTEGER */

};

// result: INFOTABLE dataShape: FileTransferJob

var result = Subsystems["FileTransferSubsystem"].Copy(params);


  • The following is the entire Java file (provided in the Java SDK download) that sets up Virtual Directories for a file transfer.
    • If you look at the custom service above to see that we are referencing the targetPath for a directory that is defined in the Java class.


package com.thingworx.javatransfer;

import com.thingworx.communications.client.ClientConfigurator;

import com.thingworx.communications.client.ConnectedThingClient;

import com.thingworx.communications.client.things.filetransfer.FileTransferVirtualThing;

public class FileTransferExample {

  // Substitute your thing name here

  private static final String ThingName = "FileTransferExample";

  public static void main(String[] args) {

  // Create a client config

  ClientConfigurator config = new ClientConfigurator();

  // Basic configuration. See SimpleClient.java for additional info.

  config.setUri("wss://localhost:8443/Thingworx/WS");

  config.setAppKey("8737c3b9-bc65-4ac8-8990-64b565487cd3");

  config.ignoreSSLErrors(true);

  try {

  ConnectedThingClient client = new ConnectedThingClient(config);

  FileTransferVirtualThing myThing = new FileTransferVirtualThing(ThingName, "File Transfer Example", client);

  // Add two virtual directories that will act as the root directories in this

  // application's virtual file system.

  myThing.addVirtualDirectory("in",  "/home/meg/files/in");

  myThing.addVirtualDirectory("out", "/home/meg/files/out");

  client.bindThing(myThing);

  client.start();

  while(!client.isShutdown()) {

  Thread.sleep(5000);

  }

  } catch(Exception e) {

  e.printStackTrace();

  }

  }

}

Let me know if you have any further questions.

Meghan

Re: Transfer file from TW Server to remote JavaSDK

A million Thanks, Meghan.

The description from your perfectly answers my question.

Yea, the code I had tried was similar to what you have provided.

But the problem was there at how I configured params.

Now it is perfectly fine, Thanks again !!!

Re: Transfer file from TW Server to remote JavaSDK

Sujith, is there any chance that you could share me your knowledge about sending files to Thingworx? I'm stucked trying to send a picture from a smartphone to a Thingworx platform and I have no idea on how to implement FileTransfer with the Android SDK.

I'll apreciate your help.

Re: Transfer file from TW Server to remote JavaSDK

Hi Josue Serrano ,

Sorry that I haven't tried tried sending files to Thingworx.

But had done a POC of sending file from Thingworx to JavaSDK, and the above threads was the guideline for that.

Re: Transfer file from TW Server to remote JavaSDK

Hi @mhollenbach,

 

After copying the zip file to the target repo, i need to extract it. Is there any default service to achieve this. I have checked the "FileTransferSubsystem" there was no desired service for this activity. Please advice.

 

Thanks and Regards,

Saran

Re: Transfer file from TW Server to remote JavaSDK

Check out your FileRepositoryThing and the ExtractZipArchive service.

 

Meghan

Re: Transfer file from TW Server to remote JavaSDK

Thanks for your reply @mhollenbach.

 

The scenario here is that we use copy service of "FileTransferSubsystem" to copy the zip file from the file repository to a connected thing. We want to extract the zip in the connected asset side. So the service "ExtractZipArchive" is not available in both the  "FileTransferSubsystem" and "RemoteThingWithTunnelsAndFileTransfer".  Even in the connected asset, there are no extraction services under FileTransfer category. Hope i have given proper explanation on our situation.

 

Regards

SaranKarthick