これは、添付ファイルを標準のチケットを作成するために、残りの要求である
{
"parameters":[
{
"assignedUserId":112233,
"subjectId":1001
},
"This content is for test",
0, "", "", "",
[
{
"filename":"file.txt",
"data":"test test RCV"
}
]
]
}
ポスト
は交換してください:$ユーザ名、$ APIKEY、自分の情報を112233値。
SoftLayer API Client for Javaを使用している場合は、添付ファイル付きの標準チケットを作成する際に問題が発生しているようですが、別の方法で試しましたが、アップロードに成功しませんでした。
しかし、私はこの問題を回避するための回避策を提供することができ、次のスクリプトを試してください:
あなたが最初にそれはこの後、ファイルをにアップロードされ、チケットを作成し、スクリプトの中で見たよう
package Tickets;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.Ticket;
import com.softlayer.api.service.container.utility.file.Attachment;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
/**
* This script creates standard ticket and attach file
*
* Important Manual Page:
* http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/createStandardTicket
* http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/addAttachedFile
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Ticket
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Utility_File_Attachment
*
* @license <http://sldn.softlayer.com/article/License>
* @authon SoftLayer Technologies, Inc. <[email protected]>
* @version 0.2.2
*/
public class CreateStandardTicket {
/**
* This is the constructor, is used to create Standard Ticket, it shows basic
* properties for creating a ticket.
*/
public CreateStandardTicket() {
// Declare your SoftLayer username and apiKey
String username = "set me";
String apiKey = "set me";
// Declare the data of the ticket you wish to submit
Long assignedUserId = new Long(112233);
boolean notifyUserOnUpdateFlag = true;
Long subjectId = new Long(1001);
String title = "New Standard Ticket for Test";
// Declare others parameters of the ticket
String contents = "New content for test";
Long attachmentId = null;
String rootPassword = "";
String controlPanelPassword = "";
String accessPort = "";
String attachmentType = "";
// Declare the name of the file that will upload to the SoftLayer API and the path where the file is located
String filename = "fileTest.txt";
String path = "C:/Users/Test/Pictures/test.txt";
// Get Api Client and SoftLayer_Ticket service
ApiClient client = new RestApiClient().withCredentials(username, apiKey);
Ticket.Service ticketService = Ticket.service(client);
// Build SoftLayer_Ticket object containing ticket information
Ticket newStandard = new Ticket();
newStandard.setAssignedUserId(assignedUserId);
newStandard.setNotifyUserOnUpdateFlag(notifyUserOnUpdateFlag);
newStandard.setSubjectId(subjectId);
newStandard.setTitle(title);
// Build SoftLayer_Container_Utility_File_Attachment object
Attachment newFile = new Attachment();
List<Attachment> attachedFiles = new ArrayList<Attachment>();
attachedFiles.add(newFile);
try {
// Creating standard ticket
Ticket ticketCreated = ticketService.createStandardTicket(newStandard, contents, attachmentId, rootPassword, controlPanelPassword, accessPort, attachedFiles, attachmentType);
ticketService = Ticket.service(client, new Long(ticketCreated.getId()));
// Reading the file in bytes
File file = new File(path);
int length = (int) file.length();
BufferedInputStream reader = new BufferedInputStream(new FileInputStream(file));
byte[] bytes = new byte[length];
reader.read(bytes, 0, length);
reader.close();
// Build SoftLayer_Container_Utility_File_Attachment object
newFile.setData(bytes);
newFile.setFilename(filename);
// Attaching the file to the ticket
com.softlayer.api.service.ticket.attachment.File result = ticketService.addAttachedFile(newFile);
System.out.println("The ticket was created successfully: " + ticketCreated.getId());
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
/**
* This is the main method which makes use of CreateStandardTicket method.
*
* @param args
* @return Nothing
*/
public static void main(String[] args) {
new CreateStandardTicket();
}
}
チケット。
本当にお役に立てば幸いです。
ありがとうございましたRuber、実際に助けてくれましたが、私たちは直接接続機能を持っていると思っていましたが、今は私たちと大丈夫です。もう一度ありがとう。 – user1312150