Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
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
Solved! Go to Solution.
Sujith,
You are correct in using the Copy service, but there are a couple of things you need to make sure are configured correctly:
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);
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
Sujith,
You are correct in using the Copy service, but there are a couple of things you need to make sure are configured correctly:
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);
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
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 !!!
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.
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.
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
Check out your FileRepositoryThing and the ExtractZipArchive service.
Meghan
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