Skip to content

Commit cb26a0e

Browse files
author
java-tester-x
committed
upload file to the server
server catch uploaded file through special php script
0 parents  commit cb26a0e

File tree

9 files changed

+361
-0
lines changed

9 files changed

+361
-0
lines changed

.gitattributes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
*.sln merge=union
7+
*.csproj merge=union
8+
*.vbproj merge=union
9+
*.fsproj merge=union
10+
*.dbproj merge=union
11+
12+
# Standard to msysgit
13+
*.doc diff=astextplain
14+
*.DOC diff=astextplain
15+
*.docx diff=astextplain
16+
*.DOCX diff=astextplain
17+
*.dot diff=astextplain
18+
*.DOT diff=astextplain
19+
*.pdf diff=astextplain
20+
*.PDF diff=astextplain
21+
*.rtf diff=astextplain
22+
*.RTF diff=astextplain

.gitignore

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#################
2+
## Eclipse
3+
#################
4+
5+
*.pydevproject
6+
.project
7+
.metadata
8+
bin/
9+
tmp/
10+
*.tmp
11+
*.bak
12+
*.swp
13+
*~.nib
14+
local.properties
15+
.classpath
16+
.settings/
17+
.loadpath
18+
19+
# External tool builders
20+
.externalToolBuilders/
21+
22+
# Locally stored "Eclipse launch configurations"
23+
*.launch
24+
25+
# CDT-specific
26+
.cproject
27+
28+
# PDT-specific
29+
.buildpath
30+
31+
32+
#################
33+
## Visual Studio
34+
#################
35+
36+
## Ignore Visual Studio temporary files, build results, and
37+
## files generated by popular Visual Studio add-ons.
38+
39+
# User-specific files
40+
*.suo
41+
*.user
42+
*.sln.docstates
43+
44+
# Build results
45+
46+
[Dd]ebug/
47+
[Rr]elease/
48+
x64/
49+
build/
50+
[Bb]in/
51+
[Oo]bj/
52+
53+
# MSTest test Results
54+
[Tt]est[Rr]esult*/
55+
[Bb]uild[Ll]og.*
56+
57+
*_i.c
58+
*_p.c
59+
*.ilk
60+
*.meta
61+
*.obj
62+
*.pch
63+
*.pdb
64+
*.pgc
65+
*.pgd
66+
*.rsp
67+
*.sbr
68+
*.tlb
69+
*.tli
70+
*.tlh
71+
*.tmp
72+
*.tmp_proj
73+
*.log
74+
*.vspscc
75+
*.vssscc
76+
.builds
77+
*.pidb
78+
*.log
79+
*.scc
80+
81+
# Visual C++ cache files
82+
ipch/
83+
*.aps
84+
*.ncb
85+
*.opensdf
86+
*.sdf
87+
*.cachefile
88+
89+
# Visual Studio profiler
90+
*.psess
91+
*.vsp
92+
*.vspx
93+
94+
# Guidance Automation Toolkit
95+
*.gpState
96+
97+
# ReSharper is a .NET coding add-in
98+
_ReSharper*/
99+
*.[Rr]e[Ss]harper
100+
101+
# TeamCity is a build add-in
102+
_TeamCity*
103+
104+
# DotCover is a Code Coverage Tool
105+
*.dotCover
106+
107+
# NCrunch
108+
*.ncrunch*
109+
.*crunch*.local.xml
110+
111+
# Installshield output folder
112+
[Ee]xpress/
113+
114+
# DocProject is a documentation generator add-in
115+
DocProject/buildhelp/
116+
DocProject/Help/*.HxT
117+
DocProject/Help/*.HxC
118+
DocProject/Help/*.hhc
119+
DocProject/Help/*.hhk
120+
DocProject/Help/*.hhp
121+
DocProject/Help/Html2
122+
DocProject/Help/html
123+
124+
# Click-Once directory
125+
publish/
126+
127+
# Publish Web Output
128+
*.Publish.xml
129+
*.pubxml
130+
131+
# NuGet Packages Directory
132+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133+
#packages/
134+
135+
# Windows Azure Build Output
136+
csx
137+
*.build.csdef
138+
139+
# Windows Store app package directory
140+
AppPackages/
141+
142+
# Others
143+
sql/
144+
*.Cache
145+
ClientBin/
146+
[Ss]tyle[Cc]op.*
147+
~$*
148+
*~
149+
*.dbmdl
150+
*.[Pp]ublish.xml
151+
*.pfx
152+
*.publishsettings
153+
154+
# RIA/Silverlight projects
155+
Generated_Code/
156+
157+
# Backup & report files from converting an old project file to a newer
158+
# Visual Studio version. Backup files are not needed, because we have git ;-)
159+
_UpgradeReport_Files/
160+
Backup*/
161+
UpgradeLog*.XML
162+
UpgradeLog*.htm
163+
164+
# SQL Server files
165+
App_Data/*.mdf
166+
App_Data/*.ldf
167+
168+
#############
169+
## Windows detritus
170+
#############
171+
172+
# Windows image file caches
173+
Thumbs.db
174+
ehthumbs.db
175+
176+
# Folder config file
177+
Desktop.ini
178+
179+
# Recycle Bin used on file shares
180+
$RECYCLE.BIN/
181+
182+
# Mac crap
183+
.DS_Store
184+
185+
186+
#############
187+
## Python
188+
#############
189+
190+
*.py[co]
191+
192+
# Packages
193+
*.egg
194+
*.egg-info
195+
dist/
196+
build/
197+
eggs/
198+
parts/
199+
var/
200+
sdist/
201+
develop-eggs/
202+
.installed.cfg
203+
204+
# Installer logs
205+
pip-log.txt
206+
207+
# Unit test / coverage reports
208+
.coverage
209+
.tox
210+
211+
#Translations
212+
*.mo
213+
214+
#Mr Developer
215+
.mr.developer.cfg

FileUploader.java

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import java.net.*;
2+
import java.io.*;
3+
4+
public class FileUploader {
5+
6+
public static void main(String[] args) throws Exception{
7+
System.out.println("Hi!");
8+
//dowload();
9+
upload();
10+
}
11+
12+
public static void dowload() throws IOException {
13+
try {
14+
URL myURL = new URL("http://orcl.rfpgu.ru");
15+
16+
BufferedReader in = new BufferedReader(new InputStreamReader(myURL.openStream()));
17+
String inputLine;
18+
while ((inputLine = in.readLine()) != null) {
19+
System.out.println(inputLine);
20+
}
21+
in.close();
22+
}
23+
catch (IOException e) {
24+
// exception handler code here
25+
// ...
26+
}
27+
}
28+
29+
public static void upload() throws IOException {
30+
URL myURL = new URL("http://orcl.rfpgu.ru/upload_1981.php");
31+
32+
String param = "value";
33+
File textFile = new File("uploads/my_start.txt");
34+
File binaryFile = new File("uploads/winter.jpg");
35+
// Just generate some unique random value.
36+
String boundary = Long.toHexString(System.currentTimeMillis());
37+
// Line separator required by multipart/form-data.
38+
String CRLF = "\r\n";
39+
String charset = "UTF-8";
40+
41+
URLConnection connection = myURL.openConnection();
42+
connection.setDoOutput(true);
43+
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
44+
45+
PrintWriter writer = null;
46+
try {
47+
OutputStream output = connection.getOutputStream();
48+
writer = new PrintWriter(new OutputStreamWriter(output, charset), true); // true = autoFlush, important!
49+
50+
// Send normal param.
51+
writer.append("--" + boundary).append(CRLF);
52+
writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
53+
writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
54+
writer.append(CRLF);
55+
writer.append(param).append(CRLF).flush();
56+
57+
// Send text file.
58+
System.out.println("textFile: "+textFile.getName());
59+
System.out.println("Content-Type: "+URLConnection.guessContentTypeFromName(textFile.getName()));
60+
writer.append("--" + boundary).append(CRLF);
61+
writer.append(
62+
"Content-Disposition: form-data; name=\"upfile\"; filename=\""
63+
+ textFile.getName() + "\"").append(CRLF);
64+
writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
65+
writer.append(CRLF).flush();
66+
BufferedReader reader = new BufferedReader(new InputStreamReader(
67+
new FileInputStream(textFile), charset)
68+
);
69+
try {
70+
for (String line; (line = reader.readLine()) != null;) {
71+
writer.append(line).append(CRLF);
72+
}
73+
} finally {
74+
try { reader.close(); } catch (IOException logOrIgnore) {}
75+
}
76+
writer.flush();
77+
78+
// Send binary file.
79+
System.out.println("binaryFile: "+binaryFile.getName());
80+
System.out.println("Content-Type: "+URLConnection.guessContentTypeFromName(binaryFile.getName()));
81+
writer.append("--" + boundary).append(CRLF);
82+
writer.append(
83+
"Content-Disposition: form-data; name=\"upfile\"; filename=\""
84+
+ binaryFile.getName() + "\"").append(CRLF);
85+
writer.append(
86+
"Content-Type: "
87+
+ URLConnection.guessContentTypeFromName(binaryFile.getName())).append(CRLF);
88+
writer.append("Content-Transfer-Encoding: binary").append(CRLF);
89+
writer.append(CRLF).flush();
90+
InputStream input = new FileInputStream(binaryFile);
91+
try {
92+
byte[] buffer = new byte[1024];
93+
for (int length = 0; (length = input.read(buffer)) > 0;) {
94+
output.write(buffer, 0, length);
95+
}
96+
output.flush(); // Important! Output cannot be closed. Close of writer will close output as well.
97+
} finally {
98+
try { input.close(); } catch (IOException logOrIgnore) {}
99+
}
100+
writer.append(CRLF).flush(); // CRLF is important! It indicates end of binary boundary.
101+
102+
// End of multipart/form-data.
103+
writer.append("--" + boundary + "--").append(CRLF);
104+
} finally {
105+
if (writer != null) writer.close();
106+
}
107+
108+
//Retrieve response
109+
BufferedReader br = new BufferedReader(
110+
new InputStreamReader(connection.getInputStream()));
111+
String line = br.readLine();
112+
while ( line != null ) {
113+
System.out.println(line);
114+
line = br.readLine();
115+
}
116+
br.close();
117+
}
118+
119+
}

runFileUploader.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
javac -Xlint:unchecked -cp .;lib/* -d bin FileUploader.java
2+
java -cp .;lib/*;bin/ FileUploader
3+
pause

uploads/blue-mountins.jpg

27.9 KB
Loading

uploads/my_start.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
define _editor = "c:\Program Files\Sublime Text 3\sublime_text.exe";
2+
set linesize 200;

uploads/sun.jpg

69.5 KB
Loading

uploads/water-signs.jpg

81.8 KB
Loading

uploads/winter.jpg

103 KB
Loading

0 commit comments

Comments
 (0)