def splitMultipart( fname, pieceSize=1048576 ):

	f = open( fname, 'rb')
	data = f.read()
	f.close()
	sha256 = hashlib.sha256(data).hexdigest()

	bytes = len(data)
	pieces = bytes/pieceSize

	if (bytes%pieceSize): pieces += 1
	
	# f = open('info.txt', 'w')
	# f.write(fname+','+'piece,'+str(pieces)+','+str(pieceSize)+"\n")
	# f.close()

	manifest = ''
	pieceNames = []
	pieceNum = 0
	for i in range(0, bytes+1, pieceSize):
		pieceNum += 1
		fn1 = "piece%s" % i
		pieceNames.append(fn1)
		f = open(fn1, 'wb')
		fn1sha=hashlib.sha256(data[i:i+ pieceSize]).hexdigest()
		print ("pieces%s: "+fn1sha) %i
		f.write(data[i:i+ pieceSize])
		f.close()
		if (manifest<>''): manifest = manifest+','
		manifest = manifest +  \
			'''{ ''' + \
			'''"piece": '''+str(pieceNum)+''', '''+ \
			'''"filename": "'''+fn1+'''", '''+ \
			'''"sha-256": "'''+fn1sha+'''", '''+ \
			'''"size": '''+str(len(data[i:i+ pieceSize]))+''', '''+ \
			'''"offset": '''+str(i)+''' '''+ \
			'''}'''
	
	jsonstr = '''{ "filename": "''' + fname + '''", "pieces": '''+str(pieces)+''', "sha-256": "'''+sha256+'''", "manifest": [ '''+manifest+''' ] }'''
	print jsonstr
dataset/ETHPy150Open wylieswanson/AgileCLU/bin/agilepostmp.py/splitMultipart/original