Ejemplo n.º 1
0
def uploadByteArray(byteArray):
    """ 
	Allows the upload of a PNG encoded as a ByteArray from Flash for 
	authenticated users. (This is used to upload cropped images from Flash.)
	"""
    user = users.get_current_user()

    # Does a photo entry exist for this user?
    photo = Photo.all().filter("user ="******"Cropped bytearray"
    photo.fileSize = len(byteArray)
    photo.fileType = "PNG"
    photo.authToken = ""
    photo.put()

    userProfile = UserProfile.all().filter("user = ", user).get()

    userProfile.hasPhoto = True
    userProfile.photo = photo
    userProfile.put()
Ejemplo n.º 2
0
	def post(self):
		authToken = self.request.get('authToken')
		
		photo = Photo.all().filter("authToken = ", authToken).get()

		#if photo == None:
		#	photo = Photo()
		#	photo.user = user

		if photo:
			logging.info("Storing photo...")
			photo.ip = self.request.remote_addr
		
			image = self.request.get('upload')

			photo.fileBlob = db.Blob(image)	
			photo.put()
			
			# Until the user crops the photo, set their hasPhoto to false 
			# so that uncropped photos don't show up in the stream.
			userProfile = UserProfile.all().filter("user = "******"Error: No such photo.")
			# Unauthorized	
			self.error(401)
Ejemplo n.º 3
0
	def get(self):
		user = users.get_current_user()
		
		if user:
			photo = Photo.all().filter("user = "******"Returning image!")
				# TODO: We really need to return the right content-type. Right now I'm returning JPEG for everything.
				self.response.headers['Content-Type'] = "image/jpeg"
				
				#logging.info(photo.fileBlob)
				
				self.response.out.write(photo.fileBlob)
			else:
				logging.info("No photo found for user, returning default.")
				self.redirect('/static/images/no_image.jpg')
		else:
			# Unauthorized
			self.error(401)
Ejemplo n.º 4
0
def getAuthToken(fileName, fileSize, fileType):
    """ 
	Return an auth token to the client. Client will send this 
	auth token back with its FileReference file upload request. 
	(This workaround is necessary because FileReference doesn't send
	session info.)
	"""

    user = users.get_current_user()

    if user:

        # Does a photo entry exist for this user?
        photo = Photo.all().filter("user ="******"First time photo upload for user. Creating photo object.")
            photo = Photo()
            photo.user = user
            photo.put()

        logging.info("fileName = " + fileName)
        logging.info("fileSize = " + str(fileSize))
        logging.info("fileType = " + fileType)

        # Store the name, size, and type of the file being uploaded.
        # TODO: Filter here for file types?
        photo.fileName = fileName
        photo.fileSize = fileSize
        photo.fileType = fileType

        # Make an auth token hash that's valid only for this photo.
        photo.authToken = md5.new(
            str(photo.key()) + fileName + str(fileSize) + fileType + datetime.utcnow().strftime("%Y%m%dT%H%M%S")
        ).hexdigest()
        photo.put()

        logging.debug("New auth token: " + photo.authToken)

        return {"authToken": photo.authToken}

    else:

        # Unauthorized.
        logging.info("Not returning auth token to unauthorized user.")
        self.error(403)