08-23-2011 07:15 AM
//Authentication succeded
//…….
//set mimetype
strMimetype = GetMimeType(strFileName);
//encode the content of the file
strFileEncContent = base64Encode(strFilePath);
//the Json string has to be created
strJson = "{filedata: {filename: \"" + strFileName + "\", \"content\": \"" + strFileEncContent + "\", \"mimetype\": \"" + strMimetype + "\"},";
strJson = strJson + "filename : \"" + strFileName + "\",";
strJson = strJson + "destination : \"" + this.locationUuid + "\",";
strJson = strJson + "description : \"" + this.tbDescription.Text + " \",";
strJson = strJson + "aspects : \"" + Constants.ASPECT_VERSIONABLE + "," + Constants.ASPECT_CLASSIFIABLE + "\",";
strJson = strJson + "uploaddirectory : \"" + "DIMS! Archive" + "\"}";
//get these setting and create a url and add the ticket.
//uploadPath is set to "http://localhost:8080/alfresco/service/api/upload"
strUri = Properties.Settings.Default.strUploadPath.ToString();
strTemp = string.Concat(strUri, "?", strTicket);
webRequest = WebRequest.Create(strTemp);
webRequest.Method = "POST";
webRequest.ContentType = "application/json";
if (strUri != "")
{
// write out the data to the web server
writeToURL(webRequest, strJson);
//read the response from the Web Server
strHtmlContent = retrieveFromURL(webRequest);
MessageBox.Show(strFilePath + " uploaded");
}
catch (Exception ex)
{
MessageBox.Show("Error: Upload error! Original error: " + ex.Message);
MessageBox.Show(ex.StackTrace);
}
Wenn jetzt Parameter fehlen würden so müsste lt. Webscript ein "Required parameters are missing" als Antwort kommen.08-23-2011 08:16 AM
08-23-2011 10:02 AM
//encode the content of the file
strFileEncContent = base64Encode(strFilePath);
strData = "filename=" + strFileName + "& content=" + strFileEncContent + "&mimetype=" + strMimetype;
strData = strData + "&filename=" + strFileName ;
strData = strData + "&destination=" + this.locationUuid;
strData = strData + "&description=" + this.tbDescription.Text;
strData = strData + "&aspects=" + Constants.ASPECT_VERSIONABLE + "," + Constants.ASPECT_CLASSIFIABLE;
strData = strData + "&uploaddirectory=" + "DIMS! Archive";
byte[] byteArray = Encoding.UTF8.GetBytes(strData);
//get these setting and create a url and add the ticket.
strUri = Properties.Settings.Default.strUploadPath.ToString();
strTemp = string.Concat(strUri, "?", strTicket);
webRequest = WebRequest.Create(strTemp);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
08-23-2011 01:32 PM
08-24-2011 03:35 AM
Hi,
wo sendest du dein byte[] byteArray an den Server?
Du musst deine bytes auch an den Server streamen.
VG, Jan
{
filedata=
{
filename = <Wert>,
content = <Wert>,
mimetype = <Wert>
},
filename = <Wert>,
destination = <Wert>,
description = <Wert>,
aspects = <Wert>,
uploaddirectory = <Wert>
}
Denn ich vermute den Fehler irgendwo beim Erstellen dieser Daten. Aber bis jetzt hat das auch nichts gebracht. Der Fehlercode 500 kommt dennoch.
try
{
//… Authentication succeded, Ticket is strTicket
// Display a wait cursor while the file is uploaded
Cursor.Current = Cursors.WaitCursor;
//now try to upload the file
strMimetype = GetMimeType(strFileName);
//encode the content of the file
strFileEncContent = base64Encode(strFilePath);
string strAspects = Constants.ASPECT_VERSIONABLE + "," + Constants.ASPECT_CLASSIFIABLE;
fileData = new ArrayList();
arrData = new ArrayList();
strFileEncContent = base64Encode(strFilePath);
strAspects = Constants.ASPECT_VERSIONABLE + "," + Constants.ASPECT_CLASSIFIABLE;
fileData = new ArrayList();
arrData = new ArrayList();
fileData.Add(String.Format("{0}={1}", "filename", strFileName));
fileData.Add(String.Format("{0}={1}", "content", strFileEncContent));
fileData.Add(String.Format("{0}={1}", "mimetype", strMimetype));
strFileData = String.Join("&", (String[])fileData.ToArray(typeof(string)));
arrData.Add(String.Format("{0}={1}", "filedata", strFileData));
arrData.Add(String.Format("{0}={1}", "filename", strFileName));
arrData.Add(String.Format("{0}={1}", "destination", this.locationUuid));
arrData.Add(String.Format("{0}={1}", "description", this.tbDescription.Text));
arrData.Add(String.Format("{0}={1}", "aspects", strAspects));
arrData.Add(String.Format("{0}={1}", "uploaddirectory", "TheArchive"));
strParameters = String.Join("&", (String[])arrData.ToArray(typeof(string)));
byte[] byteArray = Encoding.UTF8.GetBytes(strParameters);
//get these setting and create a url and add the ticket.
strUri = Properties.Settings.Default.strUploadPath.ToString();
strTemp = string.Concat(strUri, "?", strTicket);
webRequest = WebRequest.Create(strTemp);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
if (strUri != null)
{
// write out the data to the web server
writeToURL(webRequest, byteArray);
}
else
{
webRequest.ContentLength = 0;
}
// read the response from the Web Server
strHtmlContent = retrieveFromURL(webRequest);
//———————————————————————————————————-
// Reset the cursor to the default for all controls.
Cursor.Current = Cursors.Default;
MessageBox.Show(strFilePath + " uploaded");
}
catch (Exception ex)
{
MessageBox.Show("Error: Upload error! Original error: " + ex.Message);
MessageBox.Show(ex.StackTrace);
}
void writeToURL(WebRequest request, byte[] bytes)
{
request.ContentLength = bytes.Length;
// 1. Get an output stream from the request object
Stream outputStream = request.GetRequestStream();
// 2. Post the data out to the stream
outputStream.Write(bytes, 0, bytes.Length);
// 3. Close the output stream and send the data out to the web server
outputStream.Close();
}// end writeToURL method
08-24-2011 04:59 AM
08-24-2011 11:06 AM
Hi,
ok, dann lass uns hier mal eine vernünftige Analyse betreiben. Ich bin kein c#-kenner…
Schneide mal bitte deinen HTTP-Traffic mit HTTPAnalyzer o.ä. mit und poste den Request und die Response.
Alternativ solltest du dich mal am JS-Debugger von Alfresco versuchen: http://wiki.alfresco.com/wiki/Web_Scripts#Debugging_a_Controller_Script
VG, Jan
08-26-2011 10:52 AM
Hi,
du versuchts es hier mit dem falschen Mimetype (json). Das WebScript erwartet einen application/x-www-form-urlencoded POST-Body.
JSON bekommst du als Response.
VG, jan
08-28-2011 05:19 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.