Skip to content

Instantly share code, notes, and snippets.

@AbeIka
Last active October 27, 2016 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbeIka/378a6fbec280210fbc039bc266ff3719 to your computer and use it in GitHub Desktop.
Save AbeIka/378a6fbec280210fbc039bc266ff3719 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cgi
import cgitb; cgitb.enable()
import os, sys
import sssp_name
import subprocess
import boto3
import StringIO
print "Content-Type: text/html"
print
TMP_DIR = "../tmp"
def save_uploaded_file (upload_dir):
form = cgi.FieldStorage()
fileitem = form["file"]
fout = file (os.path.join(upload_dir, os.path.basename(fileitem.filename)), 'wb')
while 1:
chunk = fileitem.file.read(100000)
if not chunk: break
fout.write (chunk)
fout.close()
return(fileitem.filename)
# File Save (TMP_DIR)
file_name=save_uploaded_file(TMP_DIR)
file_pname=os.path.join(TMP_DIR, os.path.basename(file_name))
file_names=[file_pname]
# SAVDI
resp = sssp_name.virus_check(file_names)
if resp >= 2:
print "Virus found"
elif resp == 1:
print "Unable to check file"
else:
s3 = boto3.resource('s3')
s3.meta.client.upload_file(file_pname, 's3-bucketname', file_name)
os.remove(file_pname)
print "Upload ok"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment