Revision 1741
Added by skrish over 21 years ago
src/edu/ucsb/nceas/metacat/harvesterClient/MetUpload.java | ||
---|---|---|
14 | 14 |
import java.io.*; |
15 | 15 |
import java.util.*; |
16 | 16 |
|
17 |
import com.oreilly.servlet.multipart.*; |
|
17 |
import com.oreilly.servlet.multipart.FilePart; |
|
18 |
import com.oreilly.servlet.multipart.MultipartParser; |
|
19 |
import com.oreilly.servlet.multipart.ParamPart; |
|
20 |
import com.oreilly.servlet.multipart.Part; |
|
21 |
|
|
22 |
|
|
18 | 23 |
import edu.ucsb.nceas.metacat.*; |
19 | 24 |
import edu.ucsb.nceas.metacat.MetaCatUtil; |
20 | 25 |
|
... | ... | |
32 | 37 |
|
33 | 38 |
String file = new String(""); |
34 | 39 |
DBConnection dbconn = null; |
40 |
DBConnectionPool connPool = null; |
|
35 | 41 |
File dataDirectory = null; |
36 | 42 |
MetaCatUtil util = null; |
37 | 43 |
String datafilepath = null; |
... | ... | |
39 | 45 |
FilePart fPart = null; |
40 | 46 |
MultipartParser parser = new MultipartParser((HttpServletRequest)request, 1024 * 1024); |
41 | 47 |
//MultipartParser parser = new MultipartParser(request, 1024 * 1024); |
48 |
Part aPart; |
|
42 | 49 |
DocumentImplWrapper documentWrapper = null; |
43 |
Part aPart; |
|
44 | 50 |
String eml_filename=" ",docid=" "; |
45 | 51 |
StringReader xml = null; |
46 | 52 |
/*String eml_filename=" ",docid=" ";*/ |
... | ... | |
54 | 60 |
if(value == null) |
55 | 61 |
value = ""; |
56 | 62 |
formElements.put(field, value); |
57 |
docid=value; |
|
63 |
if (field.equals("docid")) |
|
64 |
docid=value; |
|
58 | 65 |
} |
59 | 66 |
} |
60 | 67 |
else if( aPart.isFile() == true ) { |
... | ... | |
65 | 72 |
//write the image to a file |
66 | 73 |
String dir = "/tmp/Upload_data"; |
67 | 74 |
File theFile = new File(dir, fileName); |
68 |
fPart.writeTo(theFile); |
|
75 |
/*fPart.writeTo(theFile);
|
|
69 | 76 |
eml_filename = dir+"/"+fileName; |
70 |
formElements.put(field, fileName); |
|
77 |
formElements.put(field, fileName);*/ |
|
78 |
break; |
|
71 | 79 |
} |
72 | 80 |
} |
73 | 81 |
} |
74 | 82 |
// out.println( formElements ); |
75 |
out.println( docid + " " + eml_filename ); |
|
76 |
out.println("EML File uploaded"); |
|
83 |
//out.println( docid + " " + eml_filename );
|
|
84 |
// out.println("EML File uploaded");
|
|
77 | 85 |
/*****************************************************/ |
78 | 86 |
|
79 | 87 |
|
... | ... | |
86 | 94 |
String username = null; |
87 | 95 |
username = (String)sess.getAttribute("username"); |
88 | 96 |
|
97 |
//out.println(username); |
|
98 |
out.println("Username is "+username+" <BR>"); |
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
//initial DBConnection pool |
|
103 |
connPool = DBConnectionPool.getInstance(); |
|
104 |
|
|
89 | 105 |
/* |
90 | 106 |
dbconn=DBConnectionPool.getDBConnection("DocumentImpl.main"); |
91 | 107 |
|
... | ... | |
104 | 120 |
|
105 | 121 |
if (DocumentImpl.getDataFileLockGrant(docid)) |
106 | 122 |
{ |
123 |
//out.println(docid); |
|
107 | 124 |
DocumentImpl.registerDocument(fileName, "BIN", docid, username); |
108 | 125 |
|
109 | 126 |
// Save the data file to disk using "docid" as the name |
... | ... | |
111 | 128 |
File newFile = new File(dataDirectory, docid); |
112 | 129 |
|
113 | 130 |
long size = fPart.writeTo(newFile); |
131 |
|
|
132 |
//out.println(docid); |
|
114 | 133 |
ForceReplicationHandler frh = new ForceReplicationHandler |
115 | 134 |
(docid, "insert", false, null); |
116 | 135 |
|
117 | 136 |
|
118 | 137 |
// set content type and other response header fields first |
119 |
out.println("success");
|
|
138 |
out.println(" EML file uploaded successfully with docid as "+docid+"<BR>" );
|
|
120 | 139 |
} |
121 | 140 |
else |
122 | 141 |
|
123 |
out.println("failure");
|
|
142 |
out.println(" EML file upload with docid as "+docid+" failed<br>");
|
|
124 | 143 |
|
125 | 144 |
|
126 | 145 |
|
Also available in: Unified diff
MetaCat Servlet changed to get correct docid